JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestX11DefaultDisplay.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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.jogl.acore;
30
31import com.jogamp.nativewindow.AbstractGraphicsDevice;
32import com.jogamp.nativewindow.NativeWindowFactory;
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLProfile;
35
36import org.junit.Assert;
37import org.junit.BeforeClass;
38import org.junit.Test;
39import org.junit.FixMethodOrder;
40import org.junit.runners.MethodSorters;
41
42import com.jogamp.newt.opengl.GLWindow;
43import com.jogamp.opengl.test.junit.jogl.demos.es1.RedSquareES1;
44import com.jogamp.opengl.test.junit.util.DumpGLInfo;
45import com.jogamp.opengl.test.junit.util.MiscUtils;
46import com.jogamp.opengl.test.junit.util.QuitAdapter;
47import com.jogamp.opengl.test.junit.util.UITestCase;
48import com.jogamp.opengl.util.Animator;
49
50/**
51 * This is a clone of TestGLPointsNEWT which uses the ability to specify
52 * the X11 default display programmatically instead of relying on the
53 * DISPLAY environment variable.
54 *
55 */
56@FixMethodOrder(MethodSorters.NAME_ASCENDING)
57public class TestX11DefaultDisplay extends UITestCase {
58 static long duration = 500; // ms
59 static int width = 512, height = 512;
60 static String x11DefaultDisplay = ":0.0";
61
62 @BeforeClass
63 public static void initClass() {
64 System.setProperty("nativewindow.x11.display.default", x11DefaultDisplay);
65 }
66
67 protected void runTestGL(final GLCapabilities caps) throws InterruptedException {
68 final GLWindow glWindow = GLWindow.create(caps);
69 Assert.assertNotNull(glWindow);
70 glWindow.setTitle(getSimpleTestName("."));
71 glWindow.setSize(width, height);
72
73 final RedSquareES1 demo = new RedSquareES1();
74 glWindow.addGLEventListener(demo);
75
77 snap.setPostSNDetail(demo.getClass().getSimpleName());
78 glWindow.addGLEventListener(snap);
79
80 final Animator animator = new Animator(glWindow);
81 final QuitAdapter quitAdapter = new QuitAdapter();
82
83 glWindow.addKeyListener(quitAdapter);
84 glWindow.addWindowListener(quitAdapter);
85
86 animator.start();
87
88 glWindow.setVisible(true);
89
90 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
91 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
92 System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
93
94 animator.setUpdateFPSFrames(60, System.err);
95 snap.setMakeSnapshot();
96
97 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
98 Thread.sleep(100);
99 }
100
101 animator.stop();
102 glWindow.destroy();
103 }
104
105 @Test
106 public void test00_DefaultDevice() {
107 final AbstractGraphicsDevice defaultDevice = GLProfile.getDefaultDevice();
108 System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
109 System.out.println("GLProfile.getDefaultDevice(): "+defaultDevice);
110 final GLProfile glp = GLProfile.getDefault();
111 System.out.println("GLProfile.getDefault(): "+glp);
112
113 final GLCapabilities caps = new GLCapabilities(glp);
114 final GLWindow glWindow = GLWindow.create(caps);
115 Assert.assertNotNull(glWindow);
116
117 glWindow.addGLEventListener(new DumpGLInfo());
118
119 glWindow.setSize(128, 128);
120 glWindow.setVisible(true);
121
122 glWindow.display();
123 glWindow.destroy();
124
126 Assert.assertEquals("X11 Default device does not match", defaultDevice.getConnection(), x11DefaultDisplay);
127 }
128 }
129
130 @Test
131 public void test01_GLDefaultRendering() throws InterruptedException {
132 final GLCapabilities caps = new GLCapabilities(null);
133 runTestGL(caps);
134 }
135
136 public static void main(final String args[]) {
137 for(int i=0; i<args.length; i++) {
138 if(args[i].equals("-time")) {
139 i++;
140 duration = MiscUtils.atol(args[i], duration);
141 } else if(args[i].equals("-x11DefaultDisplay")) {
142 x11DefaultDisplay = args[++i];
143 }
144 }
145 org.junit.runner.JUnitCore.main(TestX11DefaultDisplay.class.getName());
146 }
147}
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static final String TYPE_X11
X11 type, as retrieved with getNativeWindowType(boolean).
static String getNativeWindowType(final boolean useCustom)
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void setTitle(final String title)
Definition: GLWindow.java:297
final int getX()
Returns the current x position of this window, relative to it's parent.
Definition: GLWindow.java:436
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Definition: GLWindow.java:441
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
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 addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
Definition: GLWindow.java:266
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Definition: GLWindow.java:431
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Definition: GLWindow.java:277
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 AbstractGraphicsDevice getDefaultDevice()
This is a clone of TestGLPointsNEWT which uses the ability to specify the X11 default display program...
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final void setUpdateFPSFrames(final int frames, final PrintStream out)
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.
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.