JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestRemoteWindow01NEWT.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
31
32import org.junit.Assert;
33import org.junit.Assume;
34import org.junit.BeforeClass;
35import org.junit.Test;
36import org.junit.FixMethodOrder;
37import org.junit.runners.MethodSorters;
38
39import com.jogamp.nativewindow.*;
40
41import com.jogamp.newt.*;
42import java.io.IOException;
43
44import com.jogamp.opengl.test.junit.util.UITestCase;
45
46@FixMethodOrder(MethodSorters.NAME_ASCENDING)
47public class TestRemoteWindow01NEWT extends UITestCase {
48 static int width, height;
49 static String remoteDisplay = "localhost:0.0";
50
51 @BeforeClass
52 public static void initClass() {
54 width = 640;
55 height = 480;
56 }
57
58 static Window createWindow(final Screen screen, final Capabilities caps, final int width, final int height, final boolean onscreen, final boolean undecorated) {
59 Assert.assertNotNull(caps);
60 caps.setOnscreen(onscreen);
61 // System.out.println("Requested: "+caps);
62
63 //
64 // Create native windowing resources .. X11/Win/OSX
65 //
66 final Window window = NewtFactory.createWindow(screen, caps);
67 Assert.assertNotNull(window);
68 window.setUndecorated(onscreen && undecorated);
69 window.setSize(width, height);
70 Assert.assertEquals(false,window.isNativeValid());
71 Assert.assertEquals(false,window.isVisible());
72 window.setVisible(true);
73 Assert.assertEquals(true,window.isVisible());
74 Assert.assertEquals(true,window.isNativeValid());
75 // Assert.assertEquals(width,window.getWidth());
76 // Assert.assertEquals(height,window.getHeight());
77 // System.out.println("Created: "+window);
78
79 //
80 // Create native OpenGL resources .. XGL/WGL/CGL ..
81 // equivalent to GLAutoDrawable methods: setVisible(true)
82 //
83 final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities();
84 Assert.assertNotNull(chosenCapabilities);
85 Assert.assertTrue(chosenCapabilities.getGreenBits()>5);
86 Assert.assertTrue(chosenCapabilities.getBlueBits()>5);
87 Assert.assertTrue(chosenCapabilities.getRedBits()>5);
88 Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen);
89
90 return window;
91 }
92
93 static void destroyWindow(final Display display, final Screen screen, final Window window) {
94 if(null!=window) {
95 window.destroy();
96 }
97 if(null!=screen) {
98 screen.destroy();
99 }
100 if(null!=display) {
101 display.destroy();
102 }
103 }
104
105 @Test
106 public void testRemoteWindow01() throws InterruptedException {
107 final Capabilities caps = new Capabilities();
108 final Display display1 = NewtFactory.createDisplay(null); // local display
109 final Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0
110 final Window window1 = createWindow(screen1, caps, width, height, true /* onscreen */, false /* undecorated */);
111 window1.setVisible(true);
112
113 Assert.assertEquals(true,window1.isNativeValid());
114 Assert.assertEquals(true,window1.isVisible());
115
116 // Remote Display/Device/Screen/Window ..
117 Display display2;
118 final AbstractGraphicsDevice device2;
119 Screen screen2;
120 Window window2;
121 try {
122 display2 = NewtFactory.createDisplay(remoteDisplay);
123 display2.createNative();
124 screen2 = NewtFactory.createScreen(display2, 0); // screen 0
125 window2 = createWindow(screen2, caps, width, height, true /* onscreen */, false /* undecorated */);
126 window2.setVisible(true);
127 } catch (final NativeWindowException nwe) {
128 System.err.println(nwe);
129 Assume.assumeNoException(nwe);
130 destroyWindow(display1, screen1, window1);
131 return;
132 }
133
134 Assert.assertEquals(true,window2.isNativeValid());
135 Assert.assertEquals(true,window2.isVisible());
136
137 Thread.sleep(500); // 500 ms
138
139 destroyWindow(display1, screen1, window1);
140 destroyWindow(display2, screen2, window2);
141 }
142
143 public static void main(final String args[]) throws IOException {
144 for(int i=0; i<args.length; i++) {
145 if(args[i].equals("-display")) {
146 remoteDisplay = args[++i];
147 }
148 }
149 System.out.println("display: "+remoteDisplay);
150 final String tstname = TestRemoteWindow01NEWT.class.getName();
151 org.junit.runner.JUnitCore.main(tstname);
152 }
153
154}
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
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 void destroy()
Manually trigger the destruction, incl.
abstract void createNative()
Manual trigger the native creation, if it is not done yet.
static Display createDisplay(final String name)
Create a Display entity.
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract void destroy()
Manually trigger the destruction, incl.
CapabilitiesImmutable getChosenCapabilities()
Return the capabilities reflecting this graphics configuration, which may differ from the capabilitie...
A interface describing a graphics device in a toolkit-independent manner.
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.
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 setUndecorated(boolean value)
void destroy()
Destroys this window incl.releasing all related resources.