JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLWindowInvisiblePointer01NEWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.newt;
2
3import java.io.IOException;
4
5import com.jogamp.nativewindow.AbstractGraphicsDevice;
6import com.jogamp.opengl.GLCapabilities;
7import com.jogamp.opengl.GLCapabilitiesImmutable;
8import com.jogamp.opengl.GLEventListener;
9import com.jogamp.opengl.GLProfile;
10
11import org.junit.Assert;
12import org.junit.BeforeClass;
13import org.junit.Test;
14import org.junit.FixMethodOrder;
15import org.junit.runners.MethodSorters;
16
17import com.jogamp.newt.Screen;
18import com.jogamp.newt.opengl.GLWindow;
19import com.jogamp.opengl.test.junit.jogl.demos.es1.GearsES1;
20import com.jogamp.opengl.test.junit.util.UITestCase;
21import com.jogamp.opengl.util.Animator;
22
23@FixMethodOrder(MethodSorters.NAME_ASCENDING)
25 static GLProfile glp;
26 static int width, height;
27 static long durationPerTest = 4000; // ms
28
29 @BeforeClass
30 public static void initClass() {
31 width = 640;
32 height = 480;
33 glp = GLProfile.getDefault();
34 }
35
36 static GLWindow createWindow(final Screen screen, final GLCapabilitiesImmutable caps)
37 throws InterruptedException
38 {
39 Assert.assertNotNull(caps);
40 //
41 // Create native windowing resources .. X11/Win/OSX
42 //
43 GLWindow glWindow;
44 if(null!=screen) {
45 glWindow = GLWindow.create(screen, caps);
46 Assert.assertNotNull(glWindow);
47 } else {
48 glWindow = GLWindow.create(caps);
49 Assert.assertNotNull(glWindow);
50 }
51 glWindow.setUpdateFPSFrames(1, null);
52
53 final GLEventListener demo = new GearsES1();
54 glWindow.addGLEventListener(demo);
55
56 glWindow.setSize(512, 512);
57 glWindow.setVisible(true);
58 Assert.assertEquals(true,glWindow.isVisible());
59 Assert.assertEquals(true,glWindow.isNativeValid());
60
61 return glWindow;
62 }
63
64 static void destroyWindow(final GLWindow glWindow) {
65 if(null!=glWindow) {
66 glWindow.destroy();
67 Assert.assertEquals(false,glWindow.isNativeValid());
68 }
69 }
70
71 @Test
72 public void testWindow00() throws InterruptedException {
73 final GLCapabilities caps = new GLCapabilities(glp);
74 Assert.assertNotNull(caps);
75 final GLWindow window1 = createWindow(null, caps); // local
76 Assert.assertEquals(true,window1.isNativeValid());
77 Assert.assertEquals(true,window1.isVisible());
78 final Animator animator = new Animator(0 /* w/o AWT */);
79 animator.setUpdateFPSFrames(1, null);
80 animator.add(window1);
81 animator.start();
83
84 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1));
85
86 window1.warpPointer(width / 2, height / 2);
87 window1.requestFocus();
88 while(animator.isAnimating() && animator.getTotalFPSDuration()<durationPerTest) {
89 final boolean pointerVisibleNewVal = (animator.getTotalFPSDuration()/100)%2==0;
90 window1.setPointerVisible(pointerVisibleNewVal);
91 Assert.assertEquals(pointerVisibleNewVal,window1.isPointerVisible());
92 Thread.sleep(100);
93 }
94
95 destroyWindow(window1);
96 }
97
98 static int atoi(final String a) {
99 int i=0;
100 try {
101 i = Integer.parseInt(a);
102 } catch (final Exception ex) { ex.printStackTrace(); }
103 return i;
104 }
105
106 public static void main(final String args[]) throws IOException {
107 for(int i=0; i<args.length; i++) {
108 if(args[i].equals("-time")) {
109 durationPerTest = atoi(args[++i]);
110 }
111 }
112 System.out.println("durationPerTest: "+durationPerTest);
113 final String tstname = TestGLWindowInvisiblePointer01NEWT.class.getName();
114 org.junit.runner.JUnitCore.main(tstname);
115 }
116
117}
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 warpPointer(final int x, final int y)
Moves the pointer to x/y relative to this window's origin in pixel units.
Definition: GLWindow.java:342
final void setPointerVisible(final boolean mouseVisible)
Makes the pointer visible or invisible.
Definition: GLWindow.java:312
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 boolean isPointerVisible()
Definition: GLWindow.java:307
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
final void requestFocus()
Request focus for this native window.
Definition: GLWindow.java:416
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
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
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.