29package com.jogamp.opengl.test.junit.newt;
32import org.junit.Assert;
33import org.junit.BeforeClass;
35import org.junit.FixMethodOrder;
36import org.junit.runners.MethodSorters;
38import com.jogamp.nativewindow.util.Rectangle;
39import com.jogamp.nativewindow.util.RectangleImmutable;
40import com.jogamp.opengl.*;
42import com.jogamp.opengl.util.Animator;
43import com.jogamp.newt.*;
44import com.jogamp.newt.event.*;
45import com.jogamp.newt.opengl.*;
47import java.io.IOException;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50import com.jogamp.opengl.test.junit.util.MiscUtils;
51import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
56 static int width, height;
57 static long durationPerTest = 100;
66 static GLWindow createWindow(
final Screen screen,
final GLCapabilities caps,
final int width,
final int height,
final boolean onscreen,
final boolean undecorated,
final boolean vsync) {
67 Assert.assertNotNull(caps);
77 Assert.assertNotNull(window);
83 Assert.assertNotNull(glWindow);
87 setDemoFields(demo, glWindow);
92 glWindow.
setSize(width, height);
93 Assert.assertEquals(
false,glWindow.
isVisible());
95 Assert.assertEquals(
true,glWindow.
isVisible());
106 Assert.assertNotNull(caps2);
110 Assert.assertEquals(caps2.
isOnscreen(),onscreen);
115 static void destroyWindow(
final GLWindow glWindow) {
124 Assert.assertNotNull(caps);
125 final GLWindow window = createWindow(
null, caps, width, height,
true ,
false ,
true );
128 Assert.assertTrue(animator.
start());
132 destroyWindow(window);
134 Assert.assertEquals(
false, window.
isVisible());
135 Assert.assertEquals(
true, animator.isAnimating());
136 Assert.assertEquals(
false, animator.
isPaused());
137 Assert.assertEquals(
true, animator.
isStarted());
141 Assert.assertEquals(
false, animator.isAnimating());
142 Assert.assertEquals(
true, animator.
isPaused());
143 Assert.assertEquals(
true, animator.
isStarted());
144 Assert.assertTrue(animator.
stop());
150 Assert.assertNotNull(caps);
151 final GLWindow window = createWindow(
null, caps, width, height,
true ,
false ,
true );
154 Assert.assertTrue(animator.
start());
156 Assert.assertEquals(
false, animator.isAnimating());
157 Assert.assertEquals(
true, animator.
isPaused());
158 animator.
add(window);
162 destroyWindow(window);
163 destroyWindow(window);
164 Assert.assertEquals(
true, animator.isAnimating());
165 Assert.assertEquals(
true, animator.
isStarted());
166 Assert.assertEquals(
false, animator.
isPaused());
169 Assert.assertEquals(
false, animator.isAnimating());
170 Assert.assertEquals(
true, animator.
isStarted());
171 Assert.assertEquals(
true, animator.
isPaused());
172 Assert.assertTrue(animator.
stop());
178 Assert.assertNotNull(caps);
181 Assert.assertNotNull(display);
184 Assert.assertNotNull(screen);
185 final GLWindow window1 = createWindow(screen, caps, width, height,
true ,
false ,
false );
186 Assert.assertNotNull(window1);
189 final GLWindow window2 = createWindow(screen, caps, width-10, height-10,
true ,
false ,
true );
190 Assert.assertNotNull(window2);
196 Assert.assertEquals(
false, animator.
isStarted());
197 Assert.assertEquals(
false, animator.isAnimating());
198 Assert.assertEquals(
false, animator.
isPaused());
200 Assert.assertTrue(animator.
start());
201 Assert.assertEquals(
true, animator.
isStarted());
203 Assert.assertEquals(
false, animator.isAnimating());
204 Assert.assertEquals(
true, animator.
isPaused());
206 animator.
add(window1);
207 Assert.assertEquals(
true, animator.
isStarted());
208 Assert.assertEquals(
true, animator.isAnimating());
209 Assert.assertEquals(
false, animator.
isPaused());
211 animator.
add(window2);
212 Assert.assertEquals(
true, animator.
isStarted());
213 Assert.assertEquals(
true, animator.isAnimating());
214 Assert.assertEquals(
false, animator.
isPaused());
221 Assert.assertEquals(
true, animator.
isStarted());
222 Assert.assertEquals(
true, animator.isAnimating());
223 Assert.assertEquals(
false, animator.
isPaused());
225 while(animator.isAnimating() && animator.
getTotalFPSDuration()<durationPerTest+durationPerTest/10) {
230 Assert.assertEquals(
true, animator.
isStarted());
232 Assert.assertEquals(
false, animator.isAnimating());
233 Assert.assertEquals(
true, animator.
isPaused());
234 Assert.assertTrue(animator.
stop());
240 Assert.assertNotNull(caps);
243 Assert.assertNotNull(display1);
245 Assert.assertNotNull(display2);
246 Assert.assertNotSame(display1, display2);
249 Assert.assertNotNull(screen1);
250 final GLWindow window1 = createWindow(screen1, caps, width, height,
true ,
false ,
false );
251 Assert.assertNotNull(window1);
255 Assert.assertNotNull(screen2);
256 final GLWindow window2 = createWindow(screen2, caps, width-10, height-10,
true ,
false ,
true );
257 Assert.assertNotNull(window2);
263 Assert.assertEquals(
false, animator.
isStarted());
264 Assert.assertEquals(
false, animator.isAnimating());
265 Assert.assertEquals(
false, animator.
isPaused());
267 Assert.assertTrue(animator.
start());
268 Assert.assertEquals(
true, animator.
isStarted());
270 Assert.assertEquals(
false, animator.isAnimating());
271 Assert.assertEquals(
true, animator.
isPaused());
273 animator.
add(window1);
274 Assert.assertEquals(
true, animator.
isStarted());
275 Assert.assertEquals(
true, animator.isAnimating());
276 Assert.assertEquals(
false, animator.
isPaused());
278 animator.
add(window2);
279 Assert.assertEquals(
true, animator.
isStarted());
280 Assert.assertEquals(
true, animator.isAnimating());
281 Assert.assertEquals(
false, animator.
isPaused());
286 destroyWindow(window1);
288 Assert.assertEquals(
true, animator.
isStarted());
289 Assert.assertEquals(
true, animator.isAnimating());
290 Assert.assertEquals(
false, animator.
isPaused());
292 while(animator.isAnimating() && animator.
getTotalFPSDuration()<durationPerTest+durationPerTest/10) {
296 Assert.assertEquals(
true, animator.
isStarted());
297 Assert.assertEquals(
true, animator.isAnimating());
298 Assert.assertEquals(
false, animator.
isPaused());
300 Assert.assertEquals(
true, animator.
pause());
302 Assert.assertEquals(
true, animator.
isStarted());
303 Assert.assertEquals(
false, animator.isAnimating());
304 Assert.assertEquals(
true, animator.
isPaused());
306 Assert.assertEquals(
true, animator.
resume());
308 Assert.assertEquals(
true, animator.
isStarted());
309 Assert.assertEquals(
true, animator.isAnimating());
310 Assert.assertEquals(
false, animator.
isPaused());
312 destroyWindow(window2);
314 Assert.assertEquals(
true, animator.
isStarted());
316 Assert.assertEquals(
false, animator.isAnimating());
317 Assert.assertEquals(
true, animator.
isPaused());
319 Assert.assertTrue(animator.
stop());
320 Assert.assertEquals(
false, animator.
isStarted());
321 Assert.assertEquals(
false, animator.isAnimating());
322 Assert.assertEquals(
false, animator.
isPaused());
326 Assert.assertNotNull(demo);
327 Assert.assertNotNull(glWindow);
333 static int atoi(
final String a) {
336 i = Integer.parseInt(a);
337 }
catch (
final Exception ex) { ex.printStackTrace(); }
341 public static void main(
final String args[])
throws IOException {
342 for(
int i=0; i<args.length; i++) {
343 if(args[i].equals(
"-time")) {
344 durationPerTest = atoi(args[++i]);
348 org.junit.runner.JUnitCore.
main(tstname);
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
static Display createDisplay(final String name)
Create a Display entity.
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
abstract RectangleImmutable getViewportInWindowUnits()
See Coordinate System.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final boolean isNativeValid()
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final boolean isVisible()
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final void setUndecorated(final boolean value)
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
void testWindowDecor03TwoWinTwoDisplays()
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow)
static void main(final String args[])
void testWindowDecor02DestroyWinTwiceA()
void testWindowDecor03TwoWinOneDisplay()
void testWindowDecor01Simple()
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
final long getTotalFPSDuration()
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized void remove(final GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean pause()
Pauses this animator.
final synchronized boolean resume()
Resumes animation if paused.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
final synchronized boolean stop()
Stops this animator.
int getBlueBits()
Returns the number of bits for the color buffer's blue component.
int getRedBits()
Returns the number of bits for the color buffer's red component.
int getGreenBits()
Returns the number of bits for the color buffer's green component.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
Immutable Rectangle interface, with its position on the top-left.
Specifying NEWT's Window functionality:
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.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.