JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTranslucencyNEWT.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.caps;
30
31import com.jogamp.common.util.InterruptSource;
32import com.jogamp.junit.util.JunitTracer;
33import com.jogamp.newt.event.KeyAdapter;
34import com.jogamp.newt.event.KeyEvent;
35import com.jogamp.newt.opengl.GLWindow;
36import com.jogamp.opengl.test.junit.util.MiscUtils;
37import com.jogamp.opengl.test.junit.util.UITestCase;
38import com.jogamp.opengl.test.junit.util.QuitAdapter;
39import com.jogamp.opengl.util.Animator;
40import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
41
42import com.jogamp.opengl.GLCapabilities;
43import com.jogamp.opengl.GLProfile;
44
45import org.junit.Assert;
46import org.junit.BeforeClass;
47import org.junit.AfterClass;
48import org.junit.Test;
49import org.junit.FixMethodOrder;
50import org.junit.runners.MethodSorters;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53public class TestTranslucencyNEWT extends UITestCase {
54 static GLProfile glp;
55 static int width, height;
56
57 @BeforeClass
58 public static void initClass() {
59 /*if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2)) {
60 // exact match
61 glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2);
62 } else */ {
63 // default device, somehow ES2 compatible
64 glp = GLProfile.getGL2ES2();
65 }
66 Assert.assertNotNull(glp);
67 width = 512;
68 height = 512;
69 }
70
71 @AfterClass
72 public static void releaseClass() {
73 }
74
75 protected void runTestGL(final GLCapabilities caps, final boolean undecorated) throws InterruptedException {
76 final GLWindow glWindow = GLWindow.create(caps);
77 Assert.assertNotNull(glWindow);
78 glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+")");
79 glWindow.setUndecorated(undecorated);
80 glWindow.addGLEventListener(new GearsES2());
81
82 final Animator animator = new Animator(glWindow);
83 final QuitAdapter quitAdapter = new QuitAdapter();
84
85 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
86 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
87 glWindow.addKeyListener(quitAdapter);
88 glWindow.addWindowListener(quitAdapter);
89
90 final GLWindow f_glWindow = glWindow;
91 glWindow.addKeyListener(new KeyAdapter() {
92 public void keyReleased(final KeyEvent e) {
93 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
94 return;
95 }
96 if(e.getKeyChar()=='f') {
97 new InterruptSource.Thread() {
98 public void run() {
99 f_glWindow.setFullscreen(!f_glWindow.isFullscreen());
100 } }.start();
101 } else if(e.getKeyChar()=='d') {
102 new InterruptSource.Thread() {
103 public void run() {
104 f_glWindow.setUndecorated(!f_glWindow.isUndecorated());
105 } }.start();
106 }
107 }
108 });
109
110 glWindow.setSize(width, height);
111 glWindow.setVisible(true);
112 animator.setUpdateFPSFrames(1, null);
113 animator.start();
114
115 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
116 Thread.sleep(100);
117 }
118
119 animator.stop();
120 glWindow.destroy();
121 }
122
123 @Test
124 public void test01OpaqueDecorated() throws InterruptedException {
125 final GLCapabilities caps = new GLCapabilities(glp);
126 caps.setBackgroundOpaque(true); // default
127 runTestGL(caps, false);
128 }
129
130 @Test
131 public void test01TransparentDecorated() throws InterruptedException {
132 final GLCapabilities caps = new GLCapabilities(glp);
133 caps.setBackgroundOpaque(false);
134 // This is done implicit now ..
135 // caps.setAlphaBits(1);
136 runTestGL(caps, false);
137 }
138
139 @Test
140 public void test01TransparentUndecorated() throws InterruptedException {
141 final GLCapabilities caps = new GLCapabilities(glp);
142 caps.setBackgroundOpaque(false);
143 // This is done implicit now ..
144 // caps.setAlphaBits(1);
145 runTestGL(caps, true);
146 }
147
148 static long duration = 500; // ms
149
150 public static void main(final String args[]) {
151 boolean waitForKey = false;
152
153 for(int i=0; i<args.length; i++) {
154 if(args[i].equals("-time")) {
155 i++;
156 duration = MiscUtils.atol(args[i], duration);
157 } else if(args[i].equals("-wait")) {
158 waitForKey = true;
159 }
160 }
161 if( waitForKey ) {
162 JunitTracer.waitForKey("main");
163 }
164 org.junit.runner.JUnitCore.main(TestTranslucencyNEWT.class.getName());
165 }
166}
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
Definition: KeyEvent.java:316
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
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 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 boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
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 void setUndecorated(final boolean value)
Definition: GLWindow.java:337
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 GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
void runTestGL(final GLCapabilities caps, final boolean undecorated)
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
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.