JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestRedSquareES1NEWT.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.UITestCase;
36import com.jogamp.opengl.test.junit.util.QuitAdapter;
37
38import com.jogamp.opengl.util.Animator;
39
40import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquareES1;
41
42import com.jogamp.opengl.GLCapabilities;
43import com.jogamp.opengl.GLProfile;
44
45import org.junit.Assert;
46import org.junit.BeforeClass;
47import org.junit.AfterClass;
48import org.junit.Test;
49import org.junit.FixMethodOrder;
50import org.junit.runners.MethodSorters;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53public class TestRedSquareES1NEWT extends UITestCase {
54 static int width, height;
55 static boolean forceES2 = false;
56 static boolean forceFFPEmu = false;
57
58 @BeforeClass
59 public static void initClass() {
60 width = 512;
61 height = 512;
62 }
63
64 @AfterClass
65 public static void releaseClass() {
66 }
67
68 protected void runTestGL(final GLCapabilities caps, final boolean forceFFPEmu) throws InterruptedException {
69 final GLWindow glWindow = GLWindow.create(caps);
70 Assert.assertNotNull(glWindow);
71 glWindow.setTitle("Gears NEWT Test");
72
73 final RedSquareES1 demo = new RedSquareES1();
74 demo.setForceFFPEmu(forceFFPEmu, forceFFPEmu, false, false);
75 glWindow.addGLEventListener(demo);
77 glWindow.addGLEventListener(snap);
78
79 final Animator animator = new Animator(glWindow);
80 final QuitAdapter quitAdapter = new QuitAdapter();
81
82 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
83 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
84 glWindow.addKeyListener(quitAdapter);
85 glWindow.addWindowListener(quitAdapter);
86
87 final GLWindow f_glWindow = glWindow;
88 glWindow.addKeyListener(new KeyAdapter() {
89 public void keyReleased(final KeyEvent e) {
90 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
91 return;
92 }
93 if(e.getKeyChar()=='f') {
94 new InterruptSource.Thread() {
95 public void run() {
96 f_glWindow.setFullscreen(!f_glWindow.isFullscreen());
97 } }.start();
98 } else if(e.getKeyChar()=='d') {
99 new InterruptSource.Thread() {
100 public void run() {
101 f_glWindow.setUndecorated(!f_glWindow.isUndecorated());
102 } }.start();
103 }
104 }
105 });
106
107 glWindow.setSize(width, height);
108 glWindow.setVisible(true);
109 animator.setUpdateFPSFrames(1, null);
110 animator.start();
111 snap.setMakeSnapshot();
112
113 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
114 Thread.sleep(100);
115 }
116
117 animator.stop();
118 glWindow.destroy();
119 }
120
121 @Test
122 public void test00() throws InterruptedException {
124 runTestGL(caps, forceFFPEmu);
125 }
126
127 static long duration = 1000; // ms
128
129 public static void main(final String args[]) {
130 for(int i=0; i<args.length; i++) {
131 if(args[i].equals("-time")) {
132 i++;
133 try {
134 duration = Integer.parseInt(args[i]);
135 } catch (final Exception ex) { ex.printStackTrace(); }
136 } else if(args[i].equals("-es2")) {
137 forceES2 = true;
138 } else if(args[i].equals("-ffpemu")) {
139 forceFFPEmu = true;
140 }
141 }
142 org.junit.runner.JUnitCore.main(TestRedSquareES1NEWT.class.getName());
143 }
144}
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)
void runTestGL(final GLCapabilities caps, final boolean forceFFPEmu)
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.