JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGearsNewtAWTWrapper.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.jogl.demos.gl2.newt;
30
31import com.jogamp.nativewindow.*;
32import com.jogamp.opengl.*;
33
34import com.jogamp.opengl.util.Animator;
35import com.jogamp.opengl.test.junit.util.GLTestUtil;
36import com.jogamp.opengl.test.junit.util.MiscUtils;
37import com.jogamp.opengl.test.junit.util.UITestCase;
38import com.jogamp.opengl.test.junit.util.QuitAdapter;
39import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
40import com.jogamp.newt.*;
41import com.jogamp.newt.event.*;
42import com.jogamp.newt.opengl.*;
43
44import org.junit.Assert;
45import org.junit.BeforeClass;
46import org.junit.AfterClass;
47import org.junit.Test;
48import org.junit.FixMethodOrder;
49import org.junit.runners.MethodSorters;
50
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52public class TestGearsNewtAWTWrapper extends UITestCase {
53 static GLProfile glp;
54 static int width, height;
55 static boolean useAnimator = true;
56 static boolean doResizeTest = true;
57 static long duration = 500; // ms
58
59 @BeforeClass
60 public static void initClass() {
61 glp = GLProfile.getGL2ES2();
62 Assert.assertNotNull(glp);
63 width = 640;
64 height = 480;
65 }
66
67 @AfterClass
68 public static void releaseClass() {
69 }
70
71 protected void runTestGL(final GLCapabilitiesImmutable caps) throws InterruptedException {
72 final Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null, false); // local display
73 final Screen nScreen = NewtFactory.createScreen(nDisplay, 0); // screen 0
74 final Window nWindow = NewtFactory.createWindow(nScreen, caps);
75
76 final GLWindow glWindow = GLWindow.create(nWindow);
77 Assert.assertNotNull(glWindow);
78 glWindow.setTitle("Gears NewtAWTWrapper Test");
79
80 glWindow.addGLEventListener(new GearsES2(1));
81
82 final Animator animator = useAnimator ? new Animator(glWindow) : null;
83 final QuitAdapter quitAdapter = new QuitAdapter();
84
85 glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
86 glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
87
88 if( useAnimator ) {
89 animator.start();
90 }
91
92 int div = 3;
93 glWindow.setSize(width/div, height/div);
94 glWindow.setVisible(true);
95 if( doResizeTest ) {
96 glWindow.display();
97 final int[] expSurfaceSize = glWindow.getNativeSurface().convertToPixelUnits(new int[] { width/div, height/div });
98 Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(),
99 GLTestUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1], null));
100 Thread.sleep(600);
101
102 div = 2;
103 glWindow.setSize(width/div, height/div);
104 glWindow.display();
105 expSurfaceSize[0] = width/div;
106 expSurfaceSize[1] = height/div;
107 glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize);
108 Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(),
109 GLTestUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1], null));
110 Thread.sleep(600);
111
112 div = 1;
113 glWindow.setSize(width/div, height/div);
114 glWindow.display();
115 expSurfaceSize[0] = width/div;
116 expSurfaceSize[1] = height/div;
117 glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize);
118 Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(),
119 GLTestUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1], null));
120 Thread.sleep(600);
121 }
122
123 final long t0 = System.currentTimeMillis();
124 long t1 = t0;
125 while(!quitAdapter.shouldQuit() && t1-t0<duration) {
126 Thread.sleep(100);
127 t1 = System.currentTimeMillis();
128 }
129
130 if( useAnimator ) {
131 animator.stop();
132 }
133 glWindow.destroy();
134 }
135
136 @Test
137 public void test01() throws InterruptedException {
138 final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
139 runTestGL(caps);
140 }
141
142 public static void main(final String args[]) {
143 for(int i=0; i<args.length; i++) {
144 if(args[i].equals("-time")) {
145 i++;
146 duration = MiscUtils.atol(args[i], duration);
147 } else if(args[i].equals("-noanim")) {
148 useAnimator = false;
149 } else if(args[i].equals("-noresize")) {
150 doResizeTest = false;
151 }
152 }
153 System.err.println("useAnimator "+useAnimator);
154 org.junit.runner.JUnitCore.main(TestGearsNewtAWTWrapper.class.getName());
155 }
156}
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static final String TYPE_AWT
Generic AWT type, as retrieved with getNativeWindowType(boolean).
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.
Definition: Screen.java:58
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 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 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 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 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 GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static boolean waitForSize(final GLDrawable drawable, final int width, final int height, final Runnable waitAction)
Definition: GLTestUtil.java:72
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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
int[] convertToPixelUnits(final int[] windowUnitsAndResult)
Converts the given window units into pixel units in place.
Specifying NEWT's Window functionality:
Definition: Window.java:115
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.