JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestSwingAWT01GLn.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.Frame;
42import java.awt.Window;
43import javax.swing.JFrame;
44
45import org.junit.Before;
46import org.junit.BeforeClass;
47import org.junit.Test;
48import org.junit.FixMethodOrder;
49import org.junit.runners.MethodSorters;
50
51import static org.junit.Assume.*;
52import static javax.swing.SwingUtilities.*;
53
54/**
55 * Tests context creation + display on various kinds of Window implementations.
56 * @author Michael Bien, et. al.
57 */
58@FixMethodOrder(MethodSorters.NAME_ASCENDING)
59public class TestSwingAWT01GLn extends UITestCase {
60 private Window[] windows;
61
62
63 @BeforeClass
64 public static void startup() {
65 System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
66 }
67
68 @Before
69 public void init() {
70 windows = new Window[]{
71 new Window(null),
72 new Frame("Frame GL test"),
73 new JFrame("JFrame GL test")
74 };
75 }
76
77 protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
78
79 for (final Window window : windows) {
80
81 System.out.println("testing with "+window.getClass().getName());
82
83 // final array as mutable container hack
84 final GLCanvas[] glCanvas = new GLCanvas[1];
85
86 final Runnable test = new Runnable() {
87 public void run() {
88 glCanvas[0] = new GLCanvas(caps);
89 glCanvas[0].addGLEventListener(new GearsES2());
90 window.add(glCanvas[0]);
91
92 // Revalidate size/layout.
93 // Always validate if component added/removed.
94 // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created.
95 window.setSize(512, 512);
96 window.validate();
97
98 window.setVisible(true);
99 glCanvas[0].display();
100 }
101 };
102
103 final Runnable cleanup = new Runnable() {
104 public void run() {
105 System.out.println("cleaning up...");
106 window.setVisible(false);
107 try {
108 window.removeAll();
109 } catch (final Throwable t) {
110 assumeNoException(t);
111 t.printStackTrace();
112 }
113 window.dispose();
114 }
115
116 };
117
118 // AWT / Swing on EDT..
119 invokeAndWait(test);
120
121 final Animator animator = new Animator(glCanvas[0]);
122 animator.start();
123 Thread.sleep(1000);
124 animator.stop();
125
126 // AWT / Swing on EDT..
127 invokeAndWait(cleanup);
128 }
129 }
130
131 @Test
132 public void test01GLDefault() throws InterruptedException, InvocationTargetException {
133 final GLProfile glp = GLProfile.getDefault();
134 System.out.println("GLProfile Default: "+glp);
135 if(glp.isGL2ES2()) {
136 final GLCapabilities caps = new GLCapabilities(glp);
137 runTestGL(caps);
138 } else {
139 System.out.println("not a GL2ES2 profile");
140 }
141 }
142
143 @Test
144 public void test02GL2() throws InterruptedException, InvocationTargetException {
146 final GLProfile glprofile = GLProfile.get(GLProfile.GL2);
147 System.out.println( "GLProfile GL2: " + glprofile );
148 final GLCapabilities caps = new GLCapabilities(glprofile);
149 runTestGL(caps);
150 } else {
151 System.out.println("GL2 n/a");
152 }
153 }
154
155 public static void main(final String args[]) {
156 org.junit.runner.JUnitCore.main(TestSwingAWT01GLn.class.getName());
157 }
158}
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
final boolean isGL2ES2()
Indicates whether this profile is capable of GL2ES2.
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 GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
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