JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug551AWT.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.jogl.awt;
30
31import java.lang.reflect.InvocationTargetException;
32import com.jogamp.opengl.GLProfile;
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.awt.GLCanvas;
35import com.jogamp.opengl.util.Animator;
36
37import com.jogamp.opengl.test.junit.util.UITestCase;
38import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
39
40
41import java.awt.GraphicsConfiguration;
42import java.awt.GraphicsDevice;
43import java.awt.GraphicsEnvironment;
44import java.awt.Rectangle;
45import java.awt.Window;
46import javax.swing.JFrame;
47
48import org.junit.Test;
49import org.junit.FixMethodOrder;
50import org.junit.runners.MethodSorters;
51
52import static org.junit.Assume.*;
53import static javax.swing.SwingUtilities.*;
54
55/**
56 * Tests context creation + display on various kinds of Window implementations.
57 * @author Michael Bien, et. al.
58 */
59@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60public class TestBug551AWT extends UITestCase {
61
62 static void checkGraphicsEnvironment() {
63 Rectangle virtualBounds = new Rectangle();
64 final GraphicsEnvironment ge =GraphicsEnvironment.getLocalGraphicsEnvironment();
65 final GraphicsDevice[] gs = ge.getScreenDevices();
66
67 //write graphics devices to log
68 System.err.println("number of graphics devices " + gs.length);
69 for(int i =0 ; i < gs.length; i++) {
70 System.err.println(gs[i].toString());
71 }
72
73 //check for bounds
74 for (int j = 0; j < gs.length; j++) {
75 final GraphicsDevice gd = gs[j];
76 final GraphicsConfiguration[] gc = gd.getConfigurations();
77 for (int i=0; i < gc.length; i++) {
78 System.err.println("graphics configuration for device " + j + " is: " + gc[i].getBounds());
79 virtualBounds = virtualBounds.union(gc[i].getBounds());
80 }
81 }
82
83 }
84
85 protected void runTestGL() throws InterruptedException, InvocationTargetException {
86 final Window window = new JFrame(this.getSimpleTestName(" - "));
88
89 // final array as mutable container hack
90 final GLCanvas[] glCanvas = new GLCanvas[1];
91
92 final Runnable test = new Runnable() {
93 public void run() {
94 glCanvas[0] = new GLCanvas(caps);
95 glCanvas[0].addGLEventListener(new GearsES2());
96 window.add(glCanvas[0]);
97
98 // Revalidate size/layout.
99 // Always validate if component added/removed.
100 // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created.
101 window.setSize(512, 512);
102 window.validate();
103
104 window.setVisible(true);
105 glCanvas[0].display();
106 }
107 };
108
109 final Runnable cleanup = new Runnable() {
110 public void run() {
111 System.out.println("cleaning up...");
112 window.setVisible(false);
113 try {
114 window.removeAll();
115 } catch (final Throwable t) {
116 assumeNoException(t);
117 t.printStackTrace();
118 }
119 window.dispose();
120 }
121
122 };
123
124 // AWT / Swing on EDT..
125 invokeAndWait(test);
126
127 final Animator animator = new Animator(glCanvas[0]);
128 animator.start();
129 Thread.sleep(1000);
130 animator.stop();
131
132 // AWT / Swing on EDT..
133 invokeAndWait(cleanup);
134 }
135
136 // @Test
137 public void test01Plain() throws InterruptedException, InvocationTargetException {
138 runTestGL();
139 }
140
141 @Test
142 public void test02WithCheckGraphicsEnvironment() throws InterruptedException, InvocationTargetException {
143 checkGraphicsEnvironment();
144 runTestGL();
145 }
146
147 public static void main(final String args[]) {
148 org.junit.runner.JUnitCore.main(TestBug551AWT.class.getName());
149 }
150}
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
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
Tests context creation + display on various kinds of Window implementations.
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