JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGearsAWT.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.demos.gl2.awt;
30
31import com.jogamp.opengl.*;
32
33import com.jogamp.opengl.util.Animator;
34
35import com.jogamp.opengl.awt.GLCanvas;
36
37import com.jogamp.newt.event.awt.AWTKeyAdapter;
38import com.jogamp.newt.event.awt.AWTWindowAdapter;
39import com.jogamp.newt.event.TraceKeyAdapter;
40import com.jogamp.newt.event.TraceWindowAdapter;
41import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
42import com.jogamp.opengl.test.junit.util.UITestCase;
43import com.jogamp.opengl.test.junit.util.QuitAdapter;
44
45import java.awt.Dimension;
46import java.awt.Frame;
47import java.io.BufferedReader;
48import java.io.IOException;
49import java.io.InputStreamReader;
50import java.lang.reflect.InvocationTargetException;
51
52import org.junit.Assert;
53import org.junit.BeforeClass;
54import org.junit.AfterClass;
55import org.junit.Test;
56import org.junit.FixMethodOrder;
57import org.junit.runners.MethodSorters;
58
59@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60public class TestGearsAWT extends UITestCase {
61 static GLProfile glp;
62 static int width, height;
63 static boolean waitForKey = false;
64 static int msaaCount = 0;
65
66 @BeforeClass
67 public static void initClass() {
70 Assert.assertNotNull(glp);
71 width = 640;
72 height = 480;
73 } else {
74 setTestSupported(false);
75 }
76 // Runtime.getRuntime().traceInstructions(true);
77 // Runtime.getRuntime().traceMethodCalls(true);
78 }
79
80 @AfterClass
81 public static void releaseClass() {
82 }
83
84 protected void runTestGL(final GLCapabilities caps) throws InterruptedException, InvocationTargetException {
85 final Frame frame = new Frame("Gears AWT Test");
86 Assert.assertNotNull(frame);
87
88 final GLCanvas glCanvas = new GLCanvas(caps);
89 Assert.assertNotNull(glCanvas);
90 final Dimension glc_sz = new Dimension(width, height);
91 glCanvas.setMinimumSize(glc_sz);
92 glCanvas.setPreferredSize(glc_sz);
93 glCanvas.setSize(glc_sz);
94 frame.add(glCanvas);
95
96 glCanvas.addGLEventListener(new Gears(1));
97
98 final QuitAdapter quitAdapter = new QuitAdapter();
99 new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glCanvas).addTo(glCanvas);
100 new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame);
101
102 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
103 public void run() {
104 frame.pack();
105 frame.setVisible(true);
106 }});
107
108 final Animator animator = new Animator(glCanvas);
109 animator.setUpdateFPSFrames(60, System.err);
110 animator.start();
111
112 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
113 Thread.sleep(100);
114 }
115
116 Assert.assertNotNull(frame);
117 Assert.assertNotNull(glCanvas);
118 Assert.assertNotNull(animator);
119
120 animator.stop();
121 Assert.assertEquals(false, animator.isAnimating());
122 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
123 public void run() {
124 frame.setVisible(false);
125 }});
126 Assert.assertEquals(false, frame.isVisible());
127 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
128 public void run() {
129 frame.remove(glCanvas);
130 frame.dispose();
131 }});
132 }
133
134 @Test
135 public void test01() throws InterruptedException, InvocationTargetException {
136 final GLCapabilities caps = new GLCapabilities(glp);
137 if( msaaCount > 0 ) {
138 caps.setSampleBuffers(true);
139 caps.setNumSamples(msaaCount);
140 }
141 runTestGL(caps);
142 }
143
144 static long duration = 500; // ms
145
146 public static void main(final String args[]) {
147 for(int i=0; i<args.length; i++) {
148 if(args[i].equals("-time")) {
149 i++;
150 try {
151 duration = Integer.parseInt(args[i]);
152 } catch (final Exception ex) { ex.printStackTrace(); }
153 } else if(args[i].equals("-msaa")) {
154 i++;
155 try {
156 msaaCount = Integer.parseInt(args[i]);
157 } catch (final Exception ex) { ex.printStackTrace(); }
158 } else if(args[i].equals("-wait")) {
159 waitForKey = true;
160 }
161 }
162 if(waitForKey) {
163 waitForKey("Start Test");
164 }
165 org.junit.runner.JUnitCore.main(TestGearsAWT.class.getName());
166 }
167}
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
Specifies a set of OpenGL capabilities.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
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 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
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Definition: Gears.java:34
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 setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.