JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestWindows01NEWT.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.newt;
30
31import org.junit.Assert;
32import org.junit.BeforeClass;
33import org.junit.Test;
34import org.junit.FixMethodOrder;
35import org.junit.runners.MethodSorters;
36
37import com.jogamp.nativewindow.*;
38
39import com.jogamp.newt.*;
40import java.io.IOException;
41
42import com.jogamp.opengl.test.junit.util.UITestCase;
43
44@FixMethodOrder(MethodSorters.NAME_ASCENDING)
45public class TestWindows01NEWT extends UITestCase {
46 static int width, height;
47
48 @BeforeClass
49 public static void initClass() {
51 width = 256;
52 height = 256;
53 }
54
55 static Window createWindow(final Capabilities caps, final int x, final int y, final int width, final int height, final boolean onscreen, final boolean undecorated) throws InterruptedException {
56 final boolean userPos = x>=0 && y>=0 ; // user has specified a position
57
58 Assert.assertNotNull(caps);
59 caps.setOnscreen(onscreen);
60 // System.out.println("Requested: "+caps);
61
62 //
63 // Create native windowing resources .. X11/Win/OSX
64 //
65 final Window window = NewtFactory.createWindow(caps);
66 Assert.assertNotNull(window);
67 final Screen screen = window.getScreen();
68 final Display display = screen.getDisplay();
69 window.setUndecorated(onscreen && undecorated);
70 if(userPos) {
71 window.setPosition(x, y);
72 }
73 window.setSize(width, height);
74 Assert.assertEquals(false,window.isNativeValid());
75 Assert.assertEquals(false,window.isVisible());
76 window.setVisible(true);
77 // System.err.println("************* Created: "+window);
78
79 Assert.assertEquals(true,display.isNativeValid());
80 Assert.assertEquals(true,screen.isNativeValid());
81 Assert.assertEquals(true,window.isVisible());
82 Assert.assertEquals(true,window.isNativeValid());
83 Assert.assertEquals(width, window.getWidth());
84 Assert.assertEquals(height, window.getHeight());
85
86 /** we don't sync on position - unreliable test
87 Point p0 = window.getLocationOnScreen(null);
88 Assert.assertEquals(p0.getX(), window.getX());
89 Assert.assertEquals(p0.getY(), window.getY());
90 if(userPos) {
91 Assert.assertEquals(x, window.getX());
92 Assert.assertEquals(y, window.getY());
93 } */
94
95 final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities();
96 Assert.assertNotNull(chosenCapabilities);
97 Assert.assertTrue(chosenCapabilities.getGreenBits()>=5);
98 Assert.assertTrue(chosenCapabilities.getBlueBits()>=5);
99 Assert.assertTrue(chosenCapabilities.getRedBits()>=5);
100 Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen);
101
102 return window;
103 }
104
105 static void destroyWindow(final Window window, final boolean last) {
106 if(null==window) {
107 return;
108 }
109 final Screen screen = window.getScreen();
110 final Display display = screen.getDisplay();
111 window.destroy();
112 // System.err.println("************* Destroyed: "+window);
113 if(last) {
114 Assert.assertEquals(false,screen.isNativeValid());
115 Assert.assertEquals(false,display.isNativeValid());
116 } else {
117 Assert.assertEquals(true,screen.isNativeValid());
118 Assert.assertEquals(true,display.isNativeValid());
119 }
120 Assert.assertEquals(false,window.isNativeValid());
121 Assert.assertEquals(false,window.isVisible());
122 }
123
124
125 @Test
126 public void testWindowDecorSimpleWMPos() throws InterruptedException {
127 final Capabilities caps = new Capabilities();
128 Assert.assertNotNull(caps);
129
130 final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
131 destroyWindow(window, true);
132 }
133
134
135 @Test
136 public void testWindowDecorSimpleUserPos() throws InterruptedException {
137 final Capabilities caps = new Capabilities();
138 Assert.assertNotNull(caps);
139
140 final Window window = createWindow(caps, 100, 100, width, height, true /* onscreen */, false /* undecorated */);
141 destroyWindow(window, true);
142 }
143
144 @Test
145 public void testWindowNativeRecreate01Simple() throws InterruptedException {
146 final Capabilities caps = new Capabilities();
147 Assert.assertNotNull(caps);
148
149 final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
150 destroyWindow(window, true);
151
152 window.setVisible(true);
153 Assert.assertEquals(true,window.isNativeValid());
154 Assert.assertEquals(true,window.isVisible());
155 Assert.assertEquals(width, window.getWidth());
156 Assert.assertEquals(height, window.getHeight());
157
158 destroyWindow(window, true);
159 }
160
161 @Test
162 public void testWindowDecorDestroyWinTwiceA() throws InterruptedException {
163 final Capabilities caps = new Capabilities();
164 Assert.assertNotNull(caps);
165
166 final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
167 destroyWindow(window, true);
168 destroyWindow(window, true);
169 }
170
171 @Test
172 public void testWindowDecorTwoWin() throws InterruptedException {
173 final Capabilities caps = new Capabilities();
174 Assert.assertNotNull(caps);
175
176 final Window window1 = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
177 final Window window2 = createWindow(caps, 100, 100, width, height, true /* onscreen */, false /* undecorated */);
178 destroyWindow(window2, false);
179 destroyWindow(window1, true);
180 }
181
182 public static void main(final String args[]) throws IOException {
183 final String tstname = TestWindows01NEWT.class.getName();
184 org.junit.runner.JUnitCore.main(tstname);
185 }
186
187}
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static synchronized void initSingleton()
Static one time initialization of this factory.
abstract boolean isNativeValid()
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract Display getDisplay()
abstract boolean isNativeValid()
CapabilitiesImmutable getChosenCapabilities()
Return the capabilities reflecting this graphics configuration, which may differ from the capabilitie...
Specifies an immutable set of capabilities that a window's rendering context must support,...
int getBlueBits()
Returns the number of bits for the color buffer's blue component.
int getRedBits()
Returns the number of bits for the color buffer's red component.
int getGreenBits()
Returns the number of bits for the color buffer's green component.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.
AbstractGraphicsConfiguration getGraphicsConfiguration()
Returns the graphics configuration corresponding to this window.
int getHeight()
Returns the height of the client area excluding insets (window decorations) in window units.
int getWidth()
Returns the width of the client area excluding insets (window decorations) in window units.
Specifying NEWT's Window functionality:
Definition: Window.java:115
void setSize(int width, int height)
Sets the size of the window's client area in window units, excluding decorations.
void setVisible(boolean visible)
Calls setVisible(true, visible), i.e.
void setPosition(int x, int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
void setUndecorated(boolean value)
void destroy()
Destroys this window incl.releasing all related resources.