1 /**
2  * Copyright 2010 JogAmp Community. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  *    1. Redistributions of source code must retain the above copyright notice, this list of
8  *       conditions and the following disclaimer.
9  *
10  *    2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *       of conditions and the following disclaimer in the documentation and/or other materials
12  *       provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  * or implied, of JogAmp Community.
27  */
28 package com.jogamp.opengl.test.junit.graph.demos;
29 
30 import com.jogamp.opengl.GLCapabilities;
31 import com.jogamp.opengl.GLProfile;
32 
33 import com.jogamp.graph.curve.Region;
34 import com.jogamp.graph.curve.opengl.RenderState;
35 import com.jogamp.graph.geom.SVertex;
36 import com.jogamp.newt.event.KeyAdapter;
37 import com.jogamp.newt.event.KeyEvent;
38 import com.jogamp.newt.event.WindowAdapter;
39 import com.jogamp.newt.event.WindowEvent;
40 import com.jogamp.newt.opengl.GLWindow;
41 import com.jogamp.opengl.test.junit.util.MiscUtils;
42 import com.jogamp.opengl.util.Animator;
43 
44 public class GPUTextNewtDemo {
45     /**
46      * FIXME:
47      *
48      * If DEBUG is enabled:
49      *
50      * Caused by: com.jogamp.opengl.GLException: Thread[main-Display-X11_:0.0-1-EDT-1,5,main] glGetError() returned the following error codes after a call to glFramebufferRenderbuffer(<int> 0x8D40, <int> 0x1902, <int> 0x8D41, <int> 0x1): GL_INVALID_ENUM ( 1280 0x500),
51      * at com.jogamp.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:33961)
52      * at com.jogamp.opengl.DebugGL4bc.glFramebufferRenderbuffer(DebugGL4bc.java:33077)
53      * at jogamp.graph.curve.opengl.VBORegion2PGL3.initFBOTexture(VBORegion2PGL3.java:295)
54      */
55     static final boolean DEBUG = false;
56     static final boolean TRACE = false;
57 
58     static int SceneMSAASamples = 0;
59     static int GraphVBAASamples = 4;
60     static int GraphMSAASamples = 0;
61 
main(final String[] args)62     public static void main(final String[] args) {
63         int width = 800, height = 400;
64         int x = 10, y = 10;
65         if( 0 != args.length ) {
66             SceneMSAASamples = 0;
67             GraphMSAASamples = 0;
68             GraphVBAASamples = 0;
69 
70             for(int i=0; i<args.length; i++) {
71                 if(args[i].equals("-smsaa")) {
72                     i++;
73                     SceneMSAASamples = MiscUtils.atoi(args[i], SceneMSAASamples);
74                 } else  if(args[i].equals("-gmsaa")) {
75                     i++;
76                     GraphMSAASamples = MiscUtils.atoi(args[i], GraphMSAASamples);
77                     GraphVBAASamples = 0;
78                 } else if(args[i].equals("-gvbaa")) {
79                     i++;
80                     GraphMSAASamples = 0;
81                     GraphVBAASamples = MiscUtils.atoi(args[i], GraphVBAASamples);
82                 } else if(args[i].equals("-width")) {
83                     i++;
84                     width = MiscUtils.atoi(args[i], width);
85                 } else if(args[i].equals("-height")) {
86                     i++;
87                     height = MiscUtils.atoi(args[i], height);
88                 } else if(args[i].equals("-x")) {
89                     i++;
90                     x = MiscUtils.atoi(args[i], x);
91                 } else if(args[i].equals("-y")) {
92                     i++;
93                     y = MiscUtils.atoi(args[i], y);
94                 }
95             }
96         }
97         System.err.println("Desired win size "+width+"x"+height);
98         System.err.println("Desired win pos  "+x+"/"+y);
99         System.err.println("Scene MSAA Samples "+SceneMSAASamples);
100         System.err.println("Graph MSAA Samples "+GraphMSAASamples);
101         System.err.println("Graph VBAA Samples "+GraphVBAASamples);
102 
103         final GLProfile glp = GLProfile.getGL2ES2();
104 
105         final GLCapabilities caps = new GLCapabilities(glp);
106         caps.setAlphaBits(4);
107         if( SceneMSAASamples > 0 ) {
108             caps.setSampleBuffers(true);
109             caps.setNumSamples(SceneMSAASamples);
110         }
111         System.out.println("Requested: " + caps);
112 
113         int rmode = 0; // Region.VARIABLE_CURVE_WEIGHT_BIT;
114         int sampleCount = 0;
115         if( GraphVBAASamples > 0 ) {
116             rmode |= Region.VBAA_RENDERING_BIT;
117             sampleCount += GraphVBAASamples;
118         } else if( GraphMSAASamples > 0 ) {
119             rmode |= Region.MSAA_RENDERING_BIT;
120             sampleCount += GraphMSAASamples;
121         }
122 
123         final GLWindow window = GLWindow.create(caps);
124         window.setPosition(x, y);
125         window.setSize(width, height);
126         window.setTitle("GPU Text Newt Demo - graph[vbaa"+GraphVBAASamples+" msaa"+GraphMSAASamples+"], msaa "+SceneMSAASamples);
127 
128         final RenderState rs = RenderState.createRenderState(SVertex.factory());
129         final GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, rmode, sampleCount, true, DEBUG, TRACE);
130         // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32);
131         window.addGLEventListener(textGLListener);
132         window.setVisible(true);
133         // FPSAnimator animator = new FPSAnimator(60);
134         final Animator animator = new Animator();
135         animator.setUpdateFPSFrames(60, System.err);
136         animator.add(window);
137 
138         window.addKeyListener(new KeyAdapter() {
139             public void keyPressed(final KeyEvent arg0) {
140                 if(arg0.getKeyCode() == KeyEvent.VK_F4) {
141                     window.destroy();
142                 }
143             }
144         });
145         window.addWindowListener(new WindowAdapter() {
146             public void windowDestroyed(final WindowEvent e) {
147                 animator.stop();
148             }
149         });
150 
151         animator.start();
152     }
153 }
154