Jogamp
Bump scripts to jre1.8.0_66
[jogl.git] / src / test / com / jogamp / opengl / test / junit / jogl / demos / es2 / newt / TestGearsES2NEWT.java
1 /**
2  * Copyright 2011 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  
29 package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
30
31 import com.jogamp.newt.event.KeyAdapter;
32 import com.jogamp.newt.event.KeyEvent;
33 import com.jogamp.newt.opengl.GLWindow;
34 import com.jogamp.opengl.test.junit.util.UITestCase;
35 import com.jogamp.opengl.test.junit.util.QuitAdapter;
36
37 import com.jogamp.opengl.util.Animator;
38
39 import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
40
41 import javax.media.opengl.GLCapabilities;
42 import javax.media.opengl.GLProfile;
43
44 import org.junit.Assert;
45 import org.junit.BeforeClass;
46 import org.junit.AfterClass;
47 import org.junit.Test;
48
49 public class TestGearsES2NEWT extends UITestCase {
50     static GLProfile glp;
51     static int width, height;
52
53     @BeforeClass
54     public static void initClass() {
55         GLProfile.initSingleton(true);
56         /*if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2)) {
57             // exact match
58             glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2);
59         } else */ {
60             // default device, somehow ES2 compatible
61             glp = GLProfile.getGL2ES2(); 
62         }
63         Assert.assertNotNull(glp);
64         width  = 512;
65         height = 512;
66     }
67
68     @AfterClass
69     public static void releaseClass() {
70     }
71
72     protected void runTestGL(GLCapabilities caps, boolean undecorated) throws InterruptedException {
73         System.err.println("requested: "+caps);
74         GLWindow glWindow = GLWindow.create(caps);
75         Assert.assertNotNull(glWindow);
76         glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+")");
77         glWindow.setSize(width, height);
78         glWindow.setUndecorated(undecorated);
79         glWindow.setAlwaysOnTop(alwaysOnTop);
80         glWindow.setFullscreen(fullscreen);
81         glWindow.addGLEventListener(new GearsES2());
82
83         Animator animator = new Animator(glWindow);
84         QuitAdapter quitAdapter = new QuitAdapter();
85
86         //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
87         //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
88         glWindow.addKeyListener(quitAdapter);
89         glWindow.addWindowListener(quitAdapter);
90
91         final GLWindow f_glWindow = glWindow;
92         glWindow.addKeyListener(new KeyAdapter() {
93             public void keyTyped(KeyEvent e) {
94                 if(e.getKeyChar()=='f') {
95                     new Thread() {
96                         public void run() {
97                             System.err.println("[set fullscreen  pre]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", f "+f_glWindow.isFullscreen()+", "+f_glWindow.getInsets());
98                             f_glWindow.setFullscreen(!f_glWindow.isFullscreen());
99                             System.err.println("[set fullscreen post]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", f "+f_glWindow.isFullscreen()+", "+f_glWindow.getInsets());
100                     } }.start();
101                 } else if(e.getKeyChar()=='a') {
102                     new Thread() {
103                         public void run() {
104                             System.err.println("[set alwaysontop pre]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", a "+f_glWindow.isAlwaysOnTop()+", "+f_glWindow.getInsets());
105                             f_glWindow.setAlwaysOnTop(!f_glWindow.isAlwaysOnTop());
106                             System.err.println("[set alwaysontop post]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", a "+f_glWindow.isAlwaysOnTop()+", "+f_glWindow.getInsets());
107                     } }.start();
108                 } else if(e.getKeyChar()=='d') {
109                     new Thread() {
110                         public void run() {
111                             System.err.println("[set undecorated  pre]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", d "+f_glWindow.isUndecorated()+", "+f_glWindow.getInsets());
112                             f_glWindow.setUndecorated(!f_glWindow.isUndecorated());
113                             System.err.println("[set undecorated post]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", d "+f_glWindow.isUndecorated()+", "+f_glWindow.getInsets());
114                     } }.start();
115                 } else if(e.getKeyChar()=='s') {
116                     new Thread() {
117                         public void run() {
118                             System.err.println("[set position  pre]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", "+f_glWindow.getInsets());
119                             f_glWindow.setPosition(100, 100);
120                             System.err.println("[set position post]: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", "+f_glWindow.getInsets());
121                     } }.start();
122                 }
123             }
124         });
125
126         glWindow.setVisible(true);
127         
128         System.err.println("size/pos: "+f_glWindow.getX()+"/"+f_glWindow.getY()+" "+f_glWindow.getWidth()+"x"+f_glWindow.getHeight()+", "+f_glWindow.getInsets());
129         System.err.println("chosen: "+glWindow.getChosenCapabilities());
130         
131         animator.setUpdateFPSFrames(1, null);
132         animator.start();
133
134         while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
135             Thread.sleep(100);
136         }
137
138         animator.stop();
139         glWindow.destroy();
140     }
141
142     @Test
143     public void test01() throws InterruptedException {
144         GLCapabilities caps = new GLCapabilities(glp);
145         caps.setBackgroundOpaque(opaque);
146         runTestGL(caps, undecorated);
147     }
148
149     static long duration = 500; // ms
150     static boolean opaque = true;
151     static boolean undecorated = false;
152     static boolean alwaysOnTop = false;
153     static boolean fullscreen = false;
154
155     public static void main(String args[]) {
156         for(int i=0; i<args.length; i++) {
157             if(args[i].equals("-time")) {
158                 i++;
159                 try {
160                     duration = Integer.parseInt(args[i]);
161                 } catch (Exception ex) { ex.printStackTrace(); }
162             } else if(args[i].equals("-translucent")) {
163                 opaque = false;
164             } else if(args[i].equals("-undecorated")) {
165                 undecorated = true;
166             } else if(args[i].equals("-atop")) {
167                 alwaysOnTop = true;
168             } else if(args[i].equals("-fullscreen")) {
169                 fullscreen = true;
170             }
171         }
172         org.junit.runner.JUnitCore.main(TestGearsES2NEWT.class.getName());
173     }
174 }
http://JogAmp.org git info: FAQ, tutorial and man pages.