JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestWindows02NEWT.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.MiscUtils;
43import com.jogamp.opengl.test.junit.util.UITestCase;
44
45@FixMethodOrder(MethodSorters.NAME_ASCENDING)
46public class TestWindows02NEWT extends UITestCase {
47 static int width, height;
48 static long durationPerTest = 100; // ms
49
50 @BeforeClass
51 public static void initClass() {
53 width = 800;
54 height = 600;
55 }
56
57 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 {
58 final boolean userPos = x>=0 && y>=0 ; // user has specified a position
59
60 Assert.assertNotNull(caps);
61 caps.setOnscreen(onscreen);
62 // System.out.println("Requested: "+caps);
63
64 //
65 // Create native windowing resources .. X11/Win/OSX
66 //
67 final Window window = NewtFactory.createWindow(caps);
68 Assert.assertNotNull(window);
69 final Screen screen = window.getScreen();
70 final Display display = screen.getDisplay();
71 window.setUndecorated(onscreen && undecorated);
72 if(userPos) {
73 window.setPosition(x, y);
74 }
75 window.setSize(width, height);
76 Assert.assertEquals(false,window.isNativeValid());
77 Assert.assertEquals(false,window.isVisible());
78 window.setVisible(true);
79 // System.err.println("************* Created: "+window);
80
81 Assert.assertEquals(true,display.isNativeValid());
82 Assert.assertEquals(true,screen.isNativeValid());
83 Assert.assertEquals(true,window.isVisible());
84 Assert.assertEquals(true,window.isNativeValid());
85 Assert.assertEquals(width, window.getWidth());
86 Assert.assertEquals(height, window.getHeight());
87
88 final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities();
89 Assert.assertNotNull(chosenCapabilities);
90 Assert.assertTrue(chosenCapabilities.getGreenBits()>=5);
91 Assert.assertTrue(chosenCapabilities.getBlueBits()>=5);
92 Assert.assertTrue(chosenCapabilities.getRedBits()>=5);
93 Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen);
94
95 return window;
96 }
97
98 static void destroyWindow(final Window window, final boolean last) {
99 if(null==window) {
100 return;
101 }
102 final Screen screen = window.getScreen();
103 final Display display = screen.getDisplay();
104 window.destroy();
105 // System.err.println("************* Destroyed: "+window);
106 if(last) {
107 Assert.assertEquals(false,screen.isNativeValid());
108 Assert.assertEquals(false,display.isNativeValid());
109 } else {
110 Assert.assertEquals(true,screen.isNativeValid());
111 Assert.assertEquals(true,display.isNativeValid());
112 }
113 Assert.assertEquals(false,window.isNativeValid());
114 Assert.assertEquals(false,window.isVisible());
115 }
116
117
118 @Test
119 public void test01WindowDefault() throws InterruptedException {
120 final Capabilities caps = new Capabilities();
121 Assert.assertNotNull(caps);
122
123 final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
124 final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities();
125 System.err.println("XXX: "+chosenCapabilities);
126 for(int state=0; state*100<durationPerTest; state++) {
127 Thread.sleep(100);
128 }
129 destroyWindow(window, true);
130 }
131
132 @Test
133 public void test02WindowDefault() throws InterruptedException {
134 final Capabilities caps = new Capabilities();
135 Assert.assertNotNull(caps);
136 caps.setBackgroundOpaque(false);
137
138 final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */);
139 final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities();
140 System.err.println("XXX: "+chosenCapabilities);
141 for(int state=0; state*100<durationPerTest; state++) {
142 Thread.sleep(100);
143 }
144 destroyWindow(window, true);
145 }
146
147 public static void main(final String args[]) throws IOException {
148 for(int i=0; i<args.length; i++) {
149 if(args[i].equals("-time")) {
150 durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
151 }
152 }
153 System.out.println("durationPerTest: "+durationPerTest);
154 final String tstname = TestWindows02NEWT.class.getName();
155 org.junit.runner.JUnitCore.main(tstname);
156 }
157
158}
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
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()
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
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.