JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLWindows00NEWT.java
Go to the documentation of this file.
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
29package com.jogamp.opengl.test.junit.newt;
30
31import org.junit.Assert;
32import org.junit.BeforeClass;
33import org.junit.Test;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
36
37import com.jogamp.opengl.*;
38
39import com.jogamp.newt.*;
40import com.jogamp.newt.opengl.*;
41import java.io.IOException;
42
43import com.jogamp.opengl.test.junit.util.UITestCase;
44import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
45
46import com.jogamp.nativewindow.AbstractGraphicsDevice;
47
48@FixMethodOrder(MethodSorters.NAME_ASCENDING)
49public class TestGLWindows00NEWT extends UITestCase {
50 static GLProfile glp;
51 static int width, height;
52 static boolean manual = false;
53 static int loopVisibleToggle = 10;
54 static long durationPerTest = 100; // ms
55
56 @BeforeClass
57 public static void initClass() {
58 width = 640;
59 height = 480;
60 glp = GLProfile.getDefault();
61 }
62
63 static GLWindow createWindow(final Screen screen, final GLCapabilitiesImmutable caps, final boolean undecor)
64 throws InterruptedException
65 {
66 Assert.assertNotNull(caps);
67 //
68 // Create native windowing resources .. X11/Win/OSX
69 //
70 GLWindow glWindow;
71 if(null!=screen) {
72 glWindow = GLWindow.create(screen, caps);
73 Assert.assertNotNull(glWindow);
74 } else {
75 glWindow = GLWindow.create(caps);
76 Assert.assertNotNull(glWindow);
77 }
78 glWindow.setUpdateFPSFrames(1, null);
79
80 final GLEventListener demo = new GearsES2();
81 glWindow.addGLEventListener(demo);
82
83 glWindow.setUndecorated(undecor);
84 glWindow.setSize(512, 512);
85 System.err.println("XXX VISIBLE.0 -> TRUE");
86 glWindow.setVisible(true);
87 Assert.assertEquals(true,glWindow.isVisible());
88 Assert.assertEquals(true,glWindow.isNativeValid());
89
90 return glWindow;
91 }
92
93 static void destroyWindow(final GLWindow glWindow) {
94 if(null!=glWindow) {
95 glWindow.destroy();
96 Assert.assertEquals(false,glWindow.isNativeValid());
97 Assert.assertEquals(false,glWindow.isVisible());
98 }
99 }
100
101 @Test
102 public void test01WindowCreateSimple() throws InterruptedException {
103 if( manual ) {
104 return;
105 }
106 final GLCapabilities caps = new GLCapabilities(glp);
107 Assert.assertNotNull(caps);
108 final GLWindow window = createWindow(null, caps, false /* undecor */); // local
109 Assert.assertEquals(true,window.isNativeValid());
110 Assert.assertEquals(true,window.isVisible());
111
113 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1));
114
115 for(int state=0; state*100<durationPerTest; state++) {
116 Thread.sleep(100);
117 }
118
119 destroyWindow(window);
120 }
121
122 @Test
123 public void test02WindowCreateUndecor() throws InterruptedException {
124 if( manual ) {
125 return;
126 }
127 final GLCapabilities caps = new GLCapabilities(glp);
128 Assert.assertNotNull(caps);
129 final GLWindow window = createWindow(null, caps, true /* undecor */); // local
130 Assert.assertEquals(true,window.isNativeValid());
131 Assert.assertEquals(true,window.isVisible());
132
134 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1));
135
136 for(int state=0; state*100<durationPerTest; state++) {
137 Thread.sleep(100);
138 }
139
140 destroyWindow(window);
141 }
142
143 @Test
144 public void test11WindowSimpleToggleVisibility() throws InterruptedException {
145 test1xWindowToggleVisibility(false /* undecor */, loopVisibleToggle);
146 }
147 @Test
148 public void test12WindowUndecorToggleVisibility() throws InterruptedException {
149 if( manual ) {
150 return;
151 }
152 test1xWindowToggleVisibility(true /* undecor */, loopVisibleToggle);
153 }
154 private void test1xWindowToggleVisibility(final boolean undecor, final int loopVisibleToggle) throws InterruptedException {
155 final GLCapabilities caps = new GLCapabilities(glp);
156 Assert.assertNotNull(caps);
157 final GLWindow window = createWindow(null, caps, undecor); // local
158 Assert.assertEquals(true,window.isNativeValid());
159 Assert.assertEquals(true,window.isVisible());
160
161 window.display();
162 Assert.assertEquals(true,window.isNativeValid());
163 Assert.assertEquals(true,window.isVisible());
164 for(int state=0; state*100<durationPerTest; state++) {
165 Thread.sleep(100);
166 }
167
168 for(int i=1; i<=loopVisibleToggle; i++) {
169 System.err.println("XXX VISIBLE."+i+" -> FALSE");
170 window.setVisible(false);
171 Assert.assertEquals(true,window.isNativeValid());
172 Assert.assertEquals(false,window.isVisible());
173 for(int state=0; state*100<durationPerTest; state++) {
174 Thread.sleep(100);
175 }
176
177 window.display();
178 Assert.assertEquals(true,window.isNativeValid());
179 Assert.assertEquals(false,window.isVisible());
180
181 System.err.println("XXX VISIBLE."+i+" -> TRUE");
182 window.setVisible(true);
183 Assert.assertEquals(true,window.isNativeValid());
184 Assert.assertEquals(true,window.isVisible());
185 for(int state=0; state*100<durationPerTest; state++) {
186 Thread.sleep(100);
187 }
188 window.display();
189 Assert.assertEquals(true,window.isNativeValid());
190 Assert.assertEquals(true,window.isVisible());
191 }
192
193 destroyWindow(window);
194 }
195
196 static int atoi(final String a) {
197 int i=0;
198 try {
199 i = Integer.parseInt(a);
200 } catch (final Exception ex) { ex.printStackTrace(); }
201 return i;
202 }
203
204 public static void main(final String args[]) throws IOException {
205 for(int i=0; i<args.length; i++) {
206 if(args[i].equals("-time")) {
207 durationPerTest = atoi(args[++i]);
208 } else if(args[i].equals("-loopvt")) {
209 loopVisibleToggle = atoi(args[++i]);
210 } else if(args[i].equals("-manual")) {
211 manual = true;
212 }
213 }
214 System.out.println("durationPerTest: "+durationPerTest);
215 final String tstname = TestGLWindows00NEWT.class.getName();
216 org.junit.runner.JUnitCore.main(tstname);
217 }
218
219}
abstract AbstractGraphicsDevice getGraphicsDevice()
Return the AbstractGraphicsDevice used for depending resources lifecycle, i.e.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract Display getDisplay()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
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 void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
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 String glAvailabilityToString(final AbstractGraphicsDevice device)
Definition: GLProfile.java:333
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
A interface describing a graphics device in a toolkit-independent manner.
String getConnection()
Returns the semantic GraphicsDevice connection.
void setUpdateFPSFrames(int frames, PrintStream out)
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.