JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestLandscapeES2NEWT.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.es2.newt;
30
31import com.jogamp.newt.event.KeyAdapter;
32import com.jogamp.newt.event.KeyEvent;
33import com.jogamp.newt.opengl.GLWindow;
34import com.jogamp.opengl.test.junit.util.MiscUtils;
35import com.jogamp.opengl.test.junit.util.UITestCase;
36import com.jogamp.opengl.test.junit.util.QuitAdapter;
37import com.jogamp.opengl.util.Animator;
38import com.jogamp.opengl.util.AnimatorBase;
39import com.jogamp.opengl.test.junit.jogl.demos.es2.LandscapeES2;
40
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLProfile;
43
44import org.junit.Test;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
47
48@FixMethodOrder(MethodSorters.NAME_ASCENDING)
49public class TestLandscapeES2NEWT extends UITestCase {
50 static int width = 500, height = 290;
51 static int swapInterval = 1;
52 static boolean forceES2 = false;
53 static boolean forceGL3 = false;
54 static boolean mainRun = false;
55 static boolean exclusiveContext = false;
56 static boolean useAnimator = true;
57
58 protected void runTestGL(final GLCapabilities caps) throws InterruptedException {
59 System.err.println("requested: swapInterval "+swapInterval+", "+caps);
60 final GLWindow glWindow = GLWindow.create(caps);
61 glWindow.setTitle(getSimpleTestName("."));
62 glWindow.setSize(width, height);
63
64 final LandscapeES2 demo = new LandscapeES2(swapInterval);
65 glWindow.addGLEventListener(demo);
66
68 snap.setPostSNDetail(demo.getClass().getSimpleName());
69 glWindow.addGLEventListener(snap);
70
71 final Animator animator = useAnimator ? new Animator(0 /* w/o AWT */) : null;
72 if( useAnimator ) {
73 animator.setExclusiveContext(exclusiveContext);
74 }
75
76 final QuitAdapter quitAdapter = new QuitAdapter();
77
78 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
79 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
80 glWindow.addKeyListener(quitAdapter);
81 glWindow.addWindowListener(quitAdapter);
82
83 glWindow.addKeyListener(new KeyAdapter() {
84 @Override
85 public void keyReleased(final KeyEvent e) {
86 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
87 return;
88 }
89 if(e.getKeyChar()=='f') {
90 glWindow.invokeOnNewThread(null, false, new Runnable() {
91 @Override
92 public void run() {
93 glWindow.setFullscreen(!glWindow.isFullscreen());
94 } } );
95 } else if(e.getKeyChar()=='d') {
96 glWindow.invokeOnNewThread(null, false, new Runnable() {
97 @Override
98 public void run() {
99 glWindow.setUndecorated(!glWindow.isUndecorated());
100 } } );
101 }
102 }
103 });
104
105 if( useAnimator ) {
106 animator.add(glWindow);
107 animator.start();
108 }
109 glWindow.setVisible(true);
110 if( useAnimator ) {
111 animator.setUpdateFPSFrames(60, System.err);
112 }
113
114 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
115 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
116 System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
117
118 snap.setMakeSnapshot();
119
120 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
121 Thread.sleep(100);
122 }
123
124 if( useAnimator ) {
125 animator.stop();
126 }
127 glWindow.destroy();
128 }
129
130 @Test
131 public void test01GL2ES2() throws InterruptedException {
132 final GLProfile glp;
133 if(forceGL3) {
134 glp = GLProfile.get(GLProfile.GL3);
135 } else if(forceES2) {
137 } else {
138 glp = GLProfile.getGL2ES2();
139 }
140 final GLCapabilities caps = new GLCapabilities(glp);
141 runTestGL(caps);
142 }
143
144 @Test
145 public void test02GL3() throws InterruptedException {
146 if(mainRun) return;
147
149 System.err.println("GL3 n/a");
150 return;
151 }
152 final GLProfile glp = GLProfile.get(GLProfile.GL3);
153 final GLCapabilities caps = new GLCapabilities( glp );
154 runTestGL(caps);
155 }
156
157 static long duration = 1000; // ms
158
159 public static void main(final String args[]) {
160 mainRun = true;
161 for(int i=0; i<args.length; i++) {
162 if(args[i].equals("-time")) {
163 i++;
164 duration = MiscUtils.atol(args[i], duration);
165 } else if(args[i].equals("-vsync")) {
166 i++;
167 swapInterval = MiscUtils.atoi(args[i], swapInterval);
168 } else if(args[i].equals("-exclctx")) {
169 exclusiveContext = true;
170 } else if(args[i].equals("-noanim")) {
171 useAnimator = false;
172 } else if(args[i].equals("-es2")) {
173 forceES2 = true;
174 } else if(args[i].equals("-gl3")) {
175 forceGL3 = true;
176 }
177 }
178 System.err.println("forceES2 "+forceES2);
179 System.err.println("forceGL3 "+forceGL3);
180 org.junit.runner.JUnitCore.main(TestLandscapeES2NEWT.class.getName());
181 }
182}
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 int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void setTitle(final String title)
Definition: GLWindow.java:297
final int getX()
Returns the current x position of this window, relative to it's parent.
Definition: GLWindow.java:436
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 int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Definition: GLWindow.java:441
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
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 CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
Definition: GLWindow.java:266
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Definition: GLWindow.java:431
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
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Definition: GLWindow.java:277
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 boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
Definition: GLProfile.java:576
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized Thread setExclusiveContext(final Thread t)
Dedicate all GLAutoDrawable's context to the given exclusive context thread.
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
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.