JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGearsES1NEWT.java
Go to the documentation of this file.
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
29package com.jogamp.opengl.test.junit.jogl.demos.es1.newt;
30
31import com.jogamp.common.util.InterruptSource;
32import com.jogamp.newt.event.KeyAdapter;
33import com.jogamp.newt.event.KeyEvent;
34import com.jogamp.newt.opengl.GLWindow;
35import com.jogamp.opengl.test.junit.util.MiscUtils;
36import com.jogamp.opengl.test.junit.util.UITestCase;
37import com.jogamp.opengl.test.junit.util.QuitAdapter;
38
39import com.jogamp.opengl.util.Animator;
40
41import com.jogamp.opengl.test.junit.jogl.demos.es1.GearsES1;
42
43import com.jogamp.opengl.GLCapabilities;
44import com.jogamp.opengl.GLProfile;
45
46import org.junit.Assert;
47import org.junit.BeforeClass;
48import org.junit.AfterClass;
49import org.junit.Test;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
52
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54public class TestGearsES1NEWT extends UITestCase {
55 static int width, height;
56 static boolean forceES2 = false;
57 static boolean forceFFPEmu = false;
58 static int swapInterval = 1;
59
60 @BeforeClass
61 public static void initClass() {
62 width = 640;
63 height = 480;
64 }
65
66 @AfterClass
67 public static void releaseClass() {
68 }
69
70 protected void runTestGL(final GLCapabilities caps, final boolean forceFFPEmu) throws InterruptedException {
71 final GLWindow glWindow = GLWindow.create(caps);
72 Assert.assertNotNull(glWindow);
73 glWindow.setTitle("Gears NEWT Test");
74
75 final GearsES1 demo = new GearsES1(swapInterval);
76 demo.setForceFFPEmu(forceFFPEmu, forceFFPEmu, false, false);
77 glWindow.addGLEventListener(demo);
79 glWindow.addGLEventListener(snap);
80
81 final Animator animator = new Animator(glWindow);
82 final QuitAdapter quitAdapter = new QuitAdapter();
83
84 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
85 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
86 glWindow.addKeyListener(quitAdapter);
87 glWindow.addWindowListener(quitAdapter);
88
89 final GLWindow f_glWindow = glWindow;
90 glWindow.addKeyListener(new KeyAdapter() {
91 public void keyReleased(final KeyEvent e) {
92 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
93 return;
94 }
95 if(e.getKeyChar()=='f') {
96 new InterruptSource.Thread() {
97 public void run() {
98 f_glWindow.setFullscreen(!f_glWindow.isFullscreen());
99 } }.start();
100 } else if(e.getKeyChar()=='d') {
101 new InterruptSource.Thread() {
102 public void run() {
103 f_glWindow.setUndecorated(!f_glWindow.isUndecorated());
104 } }.start();
105 }
106 }
107 });
108
109 glWindow.setSize(width, height);
110 glWindow.setVisible(true);
111 animator.setUpdateFPSFrames(1, null);
112 animator.start();
113 snap.setMakeSnapshot();
114
115 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
116 Thread.sleep(100);
117 }
118
119 animator.stop();
120 glWindow.destroy();
121 }
122
123 @Test
124 public void test00() throws InterruptedException {
126 runTestGL(caps, forceFFPEmu);
127 }
128
129 static long duration = 500; // ms
130
131 public static void main(final String args[]) {
132 for(int i=0; i<args.length; i++) {
133 if(args[i].equals("-time")) {
134 i++;
135 try {
136 duration = Integer.parseInt(args[i]);
137 } catch (final Exception ex) { ex.printStackTrace(); }
138 } else if(args[i].equals("-vsync")) {
139 i++;
140 swapInterval = MiscUtils.atoi(args[i], swapInterval);
141 } else if(args[i].equals("-es2")) {
142 forceES2 = true;
143 } else if(args[i].equals("-ffpemu")) {
144 forceFFPEmu = true;
145 }
146 }
147 org.junit.runner.JUnitCore.main(TestGearsES1NEWT.class.getName());
148 }
149}
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
Definition: KeyEvent.java:316
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final void setUndecorated(final boolean value)
Definition: GLWindow.java:337
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
static GLProfile getGL2ES1(final AbstractGraphicsDevice device)
Returns the GL2ES1 profile implementation, hence compatible w/ GL2ES1.
Definition: GLProfile.java:883
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
void setForceFFPEmu(final boolean forceFFPEmu, final boolean verboseFFPEmu, final boolean debugFFPEmu, final boolean traceFFPEmu)
Definition: GearsES1.java:90
void runTestGL(final GLCapabilities caps, final boolean forceFFPEmu)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.