JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestAWT01GLn.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 com.jogamp.opengl.GLProfile;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.awt.GLCanvas;
34import com.jogamp.opengl.util.Animator;
35
36import com.jogamp.opengl.test.junit.util.UITestCase;
37import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
38
39import java.awt.Frame;
40
41import org.junit.Assert;
42import org.junit.Assume;
43import org.junit.BeforeClass;
44import org.junit.Test;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
47
48
49@FixMethodOrder(MethodSorters.NAME_ASCENDING)
50public class TestAWT01GLn extends UITestCase {
51 @BeforeClass
52 public static void startup() {
53 System.out.println("GLProfile "+GLProfile.glAvailabilityToString());
54 }
55
56 protected void runTestGL(final GLCapabilities caps) throws InterruptedException {
57 final Frame frame = new Frame("Texture Test");
58 Assert.assertNotNull(frame);
59
60 final GLCanvas glCanvas = new GLCanvas(caps);
61 Assert.assertNotNull(glCanvas);
62
63 glCanvas.addGLEventListener(new GearsES2());
64 frame.add(glCanvas);
65
66 try {
67 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
68 public void run() {
69 // Revalidate size/layout.
70 // Always validate if component added/removed.
71 // Ensure 1st paint of GLCanvas will have a valid size, hence drawable gets created.
72 frame.setSize(512, 512);
73 frame.validate();
74
75 frame.setVisible(true);
76 }});
77 } catch (final Throwable t) {
78 t.printStackTrace();
79 Assume.assumeNoException(t);
80 }
81
82 glCanvas.display(); // one in process display
83
84 final Animator animator = new Animator(glCanvas);
85 animator.start();
86
87 Thread.sleep(500); // 500 ms
88
89 animator.stop();
90
91 try {
92 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
93 public void run() {
94 frame.setVisible(false);
95 frame.remove(glCanvas);
96 frame.dispose();
97 }});
98 } catch (final Throwable t) {
99 t.printStackTrace();
100 Assume.assumeNoException(t);
101 }
102 }
103
104 @Test
105 public void test01GLDefault() throws InterruptedException {
106 final GLProfile glp = GLProfile.getDefault();
107 System.out.println("GLProfile Default: "+glp);
108 if(glp.isGL2ES2()) {
109 final GLCapabilities caps = new GLCapabilities(glp);
110 runTestGL(caps);
111 } else {
112 System.out.println("not a GL2ES2 profile");
113 }
114 }
115
116 @Test
117 public void test02GL2() throws InterruptedException {
119 final GLProfile glprofile = GLProfile.get(GLProfile.GL2);
120 System.out.println( "GLProfile GL2: " + glprofile );
121 final GLCapabilities caps = new GLCapabilities(glprofile);
122 runTestGL(caps);
123 } else {
124 System.out.println("GL2 n/a");
125 }
126 }
127
128 @Test
129 public void test02ES2() throws InterruptedException {
131 final GLProfile glprofile = GLProfile.get(GLProfile.GLES2);
132 System.out.println( "GLProfile GLES2: " + glprofile );
133 final GLCapabilities caps = new GLCapabilities(glprofile);
134 runTestGL(caps);
135 } else {
136 System.out.println("GLES2 n/a");
137 }
138 }
139
140 public static void main(final String args[]) {
141 org.junit.runner.JUnitCore.main(TestAWT01GLn.class.getName());
142 }
143}
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
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
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
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