JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGearsNEWT.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.ScalableSurface;
32import com.jogamp.nativewindow.util.Dimension;
33import com.jogamp.nativewindow.util.DimensionImmutable;
34import com.jogamp.nativewindow.util.Point;
35import com.jogamp.nativewindow.util.PointImmutable;
36import com.jogamp.newt.opengl.GLWindow;
37import com.jogamp.newt.opengl.util.NEWTDemoListener;
38import com.jogamp.opengl.test.junit.util.UITestCase;
39import com.jogamp.opengl.test.junit.util.MiscUtils;
40import com.jogamp.opengl.test.junit.util.QuitAdapter;
41
42import com.jogamp.opengl.util.Animator;
43
44import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLProfile;
47
48import org.junit.Assert;
49import org.junit.BeforeClass;
50import org.junit.AfterClass;
51import org.junit.Test;
52import org.junit.FixMethodOrder;
53import org.junit.runners.MethodSorters;
54
55/**
56 * <p>
57 * The demo code uses {@link NEWTDemoListener} functionality.
58 * </p>
59 * <p>
60 * Manual invocation via main allows setting each tests's duration in milliseconds, e.g.{@code -duration 10000}.
61 * </p>
62 */
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
64public class TestGearsNEWT extends UITestCase {
65 static GLProfile glp;
66 static PointImmutable wpos;
67 static DimensionImmutable wsize;
68 static float[] reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
69
70 @BeforeClass
71 public static void initClass() {
74 Assert.assertNotNull(glp);
75 if(null == wsize) {
76 wsize = new Dimension(640, 480);
77 }
78 } else {
79 setTestSupported(false);
80 }
81 }
82
83 @AfterClass
84 public static void releaseClass() {
85 }
86
87 protected void runTestGL(final GLCapabilities caps) throws InterruptedException {
88 final GLWindow glWindow = GLWindow.create(caps);
89 Assert.assertNotNull(glWindow);
90 glWindow.setTitle("Gears NEWT Test");
91
92 glWindow.addGLEventListener(new Gears());
93
94 final Animator animator = new Animator(glWindow);
95 final QuitAdapter quitAdapter = new QuitAdapter();
96
97 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
98 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
99 glWindow.addKeyListener(quitAdapter);
100 glWindow.addWindowListener(quitAdapter);
101
102 final NEWTDemoListener newtDemoListener = new NEWTDemoListener(glWindow);
103 glWindow.addKeyListener(newtDemoListener);
104 glWindow.addMouseListener(newtDemoListener);
105
106 glWindow.setSize(wsize.getWidth(), wsize.getHeight());
107 if(null != wpos) {
108 glWindow.setPosition(wpos.getX(), wpos.getY());
109 }
110 glWindow.setSurfaceScale(reqSurfacePixelScale);
111 final float[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new float[2]);
112
113 glWindow.setVisible(true);
114 animator.setUpdateFPSFrames(1, null);
115 animator.start();
116
117 System.err.println("Window Current State : "+glWindow.getStateMaskString());
118 System.err.println("Window Supported States: "+glWindow.getSupportedStateMaskString());
119 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
120 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
121 System.err.println("window insets: "+glWindow.getInsets());
122 System.err.println("window bounds (window): "+glWindow.getBounds());
123 System.err.println("window bounds (pixels): "+glWindow.getSurfaceBounds());
124
125 final float[] hasSurfacePixelScale1 = glWindow.getCurrentSurfaceScale(new float[2]);
126 System.err.println("HiDPI PixelScale: "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+
127 valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
128 hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
129
130 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
131 Thread.sleep(100);
132 }
133
134 animator.stop();
135 glWindow.destroy();
136 }
137
138 @Test
139 public void test01() throws InterruptedException {
140 final GLCapabilities caps = new GLCapabilities(glp);
141 runTestGL(caps);
142 }
143
144 static long duration = 500; // ms
145
146 public static void main(final String args[]) {
147 int x=0, y=0, w=640, h=480;
148 boolean usePos = false;
149
150 for(int i=0; i<args.length; i++) {
151 if(args[i].equals("-time")) {
152 i++;
153 try {
154 duration = Integer.parseInt(args[i]);
155 } catch (final Exception ex) { ex.printStackTrace(); }
156 } else if(args[i].equals("-width")) {
157 i++;
158 w = MiscUtils.atoi(args[i], w);
159 } else if(args[i].equals("-height")) {
160 i++;
161 h = MiscUtils.atoi(args[i], h);
162 } else if(args[i].equals("-x")) {
163 i++;
164 x = MiscUtils.atoi(args[i], x);
165 usePos = true;
166 } else if(args[i].equals("-y")) {
167 i++;
168 y = MiscUtils.atoi(args[i], y);
169 usePos = true;
170 } else if(args[i].equals("-pixelScale")) {
171 i++;
172 final float pS = MiscUtils.atof(args[i], reqSurfacePixelScale[0]);
173 reqSurfacePixelScale[0] = pS;
174 reqSurfacePixelScale[1] = pS;
175 }
176 }
177 wsize = new Dimension(w, h);
178 if(usePos) {
179 wpos = new Point(x, y);
180 }
181 System.err.println("position "+wpos);
182 System.err.println("size "+wsize);
183 org.junit.runner.JUnitCore.main(TestGearsNEWT.class.getName());
184 }
185}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final String getStateMaskString()
Returns a string representation of the current state mask.
Definition: GLWindow.java:246
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
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.
Definition: GLWindow.java:525
final void setTitle(final String title)
Definition: GLWindow.java:297
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.
Definition: GLWindow.java:500
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 float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
Definition: GLWindow.java:505
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 String getSupportedStateMaskString()
Returns a string representation of the supported state mask.
Definition: GLWindow.java:256
final Rectangle getSurfaceBounds()
Returns a newly created Rectangle containing window's surface origin and size in pixel units.
Definition: GLWindow.java:471
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
Definition: GLWindow.java:456
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 boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
Definition: GLWindow.java:495
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 GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
static float atof(final String str, final float def)
Definition: MiscUtils.java:75
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
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
Adding mutable surface pixel scale property to implementing class, usually to a NativeSurface impleme...
static final float AUTOMAX_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in maximum platform dependent pixel-scale,...
Immutable Dimension Interface, consisting of it's read only components:
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.