JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTranslucentChildWindowBug632NEWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.newt.parenting;
2
3import java.io.IOException;
4
5import com.jogamp.nativewindow.AbstractGraphicsDevice;
6import com.jogamp.nativewindow.NativeWindow;
7import com.jogamp.opengl.GLCapabilities;
8import com.jogamp.opengl.GLCapabilitiesImmutable;
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.opengl.GLWindow;
18import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
19import com.jogamp.opengl.test.junit.util.MiscUtils;
20import com.jogamp.opengl.test.junit.util.UITestCase;
21import com.jogamp.opengl.util.Animator;
22
23@FixMethodOrder(MethodSorters.NAME_ASCENDING)
25 static long durationPerTest = 2*300;
26 static GLProfile glp;
27 static boolean opaque;
28
29 @BeforeClass
30 public static void initClass() {
31 glp = GLProfile.getDefault();
32 opaque = false;
33 }
34
35 static GLWindow createParentWindow(final GLCapabilitiesImmutable caps, final int width, final int height)
36 throws InterruptedException
37 {
38 Assert.assertNotNull(caps);
39 //
40 // Create native windowing resources .. X11/Win/OSX
41 //
42 GLWindow glWindow;
43 glWindow = GLWindow.create(caps);
44 Assert.assertNotNull(glWindow);
45
46 glWindow.setTitle("NEWT Parenting Window Test");
47
48 glWindow.addGLEventListener(new GearsES2(1));
49
50 glWindow.setSize(width, height);
51 glWindow.setVisible(true);
52 Assert.assertEquals(true,glWindow.isVisible());
53 Assert.assertEquals(true,glWindow.isNativeValid());
54
55 return glWindow;
56 }
57
58 static GLWindow createNestedWindow(final NativeWindow nativeParentWindow, final GLCapabilitiesImmutable caps, final int x, final int y, final int width, final int height)
59 throws InterruptedException {
60
61 Assert.assertNotNull(nativeParentWindow);
62 Assert.assertNotNull(caps);
63 //
64 // Create native windowing resources .. X11/Win/OSX
65 //
66 GLWindow glWindow;
67 glWindow = GLWindow.create(nativeParentWindow, caps);
68 Assert.assertNotNull(glWindow);
69
70 glWindow.setTitle("NEWT Parenting Window Test");
71
72 glWindow.addGLEventListener(new GearsES2(1));
73
74 glWindow.setPosition(x, y);
75 glWindow.setSize(width, height);
76 glWindow.setVisible(true);
77 Assert.assertEquals(true,glWindow.isVisible());
78 Assert.assertEquals(true,glWindow.isNativeValid());
79
80 return glWindow;
81 }
82
83 static void destroyWindow(final GLWindow glWindow) {
84 if(null!=glWindow) {
85 glWindow.destroy();
86 Assert.assertEquals(false,glWindow.isNativeValid());
87 }
88 }
89
90 @Test
91 public void testWindow00() throws InterruptedException {
92 final Animator animator = new Animator(0 /* w/o AWT */);
93
94 final GLCapabilities caps = new GLCapabilities(glp);
95 Assert.assertNotNull(caps);
96 caps.setBackgroundOpaque(opaque);
97 final GLWindow window1 = createParentWindow(caps, 400, 400);
98 Assert.assertEquals(true,window1.isNativeValid());
99 Assert.assertEquals(true,window1.isVisible());
100 animator.add(window1);
101
102 final GLWindow window2 = createNestedWindow(window1, caps, 400-300, 400-300, 300, 300);
103 Assert.assertEquals(true,window2.isNativeValid());
104 Assert.assertEquals(true,window2.isVisible());
105 animator.add(window2);
106
107 animator.start();
108
109 final AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice();
110
111 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1));
112
113 Thread.sleep(durationPerTest/2);
114
115 window1.setSize(512, 512);
116 window2.setPosition(512-300, 512-300);
117
118 Thread.sleep(durationPerTest/2);
119
120 animator.stop();
121
122 destroyWindow(window2);
123 destroyWindow(window1);
124 }
125
126 public static void main(final String[] args) throws IOException {
127 for(int i=0; i<args.length; i++) {
128 if(args[i].equals("-time")) {
129 durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
130 }
131 }
132 final String testName = TestTranslucentChildWindowBug632NEWT.class.getName();
133 org.junit.runner.JUnitCore.main(testName);
134 }
135}
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
abstract AbstractGraphicsDevice getGraphicsDevice()
Return the AbstractGraphicsDevice used for depending resources lifecycle, i.e.
abstract Display getDisplay()
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 setTitle(final String title)
Definition: GLWindow.java:297
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 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 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
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
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
A interface describing a graphics device in a toolkit-independent manner.
String getConnection()
Returns the semantic GraphicsDevice connection.
Extend the NativeSurface interface with windowing information such as window-handle,...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.