JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLWindows03NEWTAnimResize.java
Go to the documentation of this file.
1/**
2 * Copyright 2013 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
31
32import java.io.IOException;
33
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLCapabilitiesImmutable;
36import com.jogamp.opengl.GLEventListener;
37import com.jogamp.opengl.GLProfile;
38
39import org.junit.Assert;
40import org.junit.BeforeClass;
41import org.junit.FixMethodOrder;
42import org.junit.Test;
43import org.junit.runners.MethodSorters;
44
45import com.jogamp.newt.event.TraceWindowAdapter;
46import com.jogamp.newt.opengl.GLWindow;
47import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
48import com.jogamp.opengl.test.junit.util.MiscUtils;
49import com.jogamp.opengl.test.junit.util.UITestCase;
50import com.jogamp.opengl.util.Animator;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54 static GLProfile glp;
55 static int step = 4;
56 static int width, height;
57 static long durationPerTest = step*500; // ms
58
59 @BeforeClass
60 public static void initClass() {
61 width = 800;
62 height = 600;
63 glp = GLProfile.getDefault();
64 }
65
66 static void test(final GLCapabilitiesImmutable caps, final boolean undecorated) throws InterruptedException {
67 Assert.assertNotNull(caps);
68
69 //
70 // Create native windowing resources .. X11/Win/OSX
71 //
72 final GLWindow glWindow = GLWindow.create(caps);
73
74 glWindow.setUpdateFPSFrames(1, null);
75 Assert.assertNotNull(glWindow);
76 glWindow.setUndecorated(undecorated);
77
78 final GLEventListener demo = new GearsES2(1);
79 glWindow.addGLEventListener(demo);
81 Assert.assertEquals(false,glWindow.isNativeValid());
82
83 glWindow.setPosition(100, 100);
84 glWindow.setSize(width/step, height/step);
85 Assert.assertEquals(false,glWindow.isVisible());
86 glWindow.setVisible(true);
87 Assert.assertEquals(true,glWindow.isVisible());
88 Assert.assertEquals(true,glWindow.isNativeValid());
89
90 final Animator animator = new Animator(glWindow);
91 animator.setUpdateFPSFrames(1, null);
92 Assert.assertTrue(animator.start());
93
94 int step_i = 0;
95 for(int i=0; i<durationPerTest; i+=50) {
96 Thread.sleep(50);
97 final int j = (int) ( i / (durationPerTest/step) ) + 1;
98 if(j>step_i) {
99 final int w = width/step * j;
100 final int h = height/step * j;
101 System.err.println("resize: "+step_i+" -> "+j+" - "+w+"x"+h);
102 glWindow.setSize(w, h);
103 step_i = j;
104 }
105 }
106 Thread.sleep(50);
107
108 animator.stop();
109 glWindow.destroy();
110 Assert.assertEquals(false, glWindow.isNativeValid());
111 Assert.assertEquals(false, glWindow.isVisible());
112 }
113
114 @Test
115 public void test01WindowDecor() throws InterruptedException {
116 final GLCapabilities caps = new GLCapabilities(glp);
117 Assert.assertNotNull(caps);
118 test(caps, false /* undecorated */);
119 }
120
121 @Test
122 public void test02WindowUndecor() throws InterruptedException {
123 final GLCapabilities caps = new GLCapabilities(glp);
124 Assert.assertNotNull(caps);
125 test(caps, true /* undecorated */);
126 }
127
128 public static void main(final String args[]) throws IOException {
129 for(int i=0; i<args.length; i++) {
130 if(args[i].equals("-time")) {
131 durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
132 }
133 }
134 final String tstname = TestGLWindows03NEWTAnimResize.class.getName();
135 org.junit.runner.JUnitCore.main(tstname);
136 }
137
138}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
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 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 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 GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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
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.