29package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt;
31import com.jogamp.opengl.*;
33import com.jogamp.newt.event.KeyEvent;
34import com.jogamp.newt.event.TraceKeyAdapter;
35import com.jogamp.newt.event.TraceWindowAdapter;
36import com.jogamp.newt.event.awt.AWTKeyAdapter;
37import com.jogamp.newt.event.awt.AWTWindowAdapter;
38import com.jogamp.opengl.util.FPSAnimator;
40import com.jogamp.opengl.awt.GLJPanel;
42import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
43import com.jogamp.opengl.test.junit.util.MiscUtils;
44import com.jogamp.opengl.test.junit.util.QuitAdapter;
45import com.jogamp.opengl.test.junit.util.UITestCase;
47import java.awt.AWTException;
48import java.awt.BorderLayout;
49import java.awt.Dimension;
50import java.lang.reflect.InvocationTargetException;
52import javax.swing.JFrame;
53import javax.swing.SwingUtilities;
55import org.junit.Assert;
56import org.junit.BeforeClass;
57import org.junit.AfterClass;
59import org.junit.FixMethodOrder;
60import org.junit.runners.MethodSorters;
62@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65 static int width, height;
66 static boolean shallUsePBuffer =
false;
67 static boolean shallUseBitmap =
false;
68 static boolean useMSAA =
false;
69 static int swapInterval = 0;
70 static boolean useAnimator =
true;
71 static boolean manualTest =
false;
77 Assert.assertNotNull(glp);
81 setTestSupported(
false);
90 throws AWTException, InterruptedException, InvocationTargetException
92 final JFrame frame =
new JFrame(
"Swing GLJPanel");
93 Assert.assertNotNull(frame);
96 Assert.assertNotNull(glJPanel);
97 final Dimension glc_sz =
new Dimension(width, height);
98 glJPanel.setMinimumSize(glc_sz);
99 glJPanel.setPreferredSize(glc_sz);
107 SwingUtilities.invokeAndWait(
new Runnable() {
109 frame.getContentPane().add(glJPanel, BorderLayout.CENTER);
110 frame.getContentPane().validate();
112 frame.setVisible(
true);
118 Assert.assertEquals(
true, animator.isAnimating());
127 public void keyPressed(
final KeyEvent e) {
145 System.err.println(
"[set MSAA "+msaa+
" Caps had]: "+capsPre);
146 System.err.println(
"[set MSAA "+msaa+
" Caps new]: "+capsNew);
147 System.err.println(
"XXX-A1: "+animator.
toString());
149 System.err.println(
"XXX-A2: "+animator.
toString());
150 System.err.println(
"XXX: "+glJPanel.
toString());
165 System.err.println(
"[set Bitmap "+bmp+
" Caps had]: "+capsPre);
166 System.err.println(
"[set Bitmap "+bmp+
" Caps new]: "+capsNew);
167 System.err.println(
"XXX-A1: "+animator.
toString());
169 System.err.println(
"XXX-A2: "+animator.
toString());
170 System.err.println(
"XXX: "+glJPanel.
toString());
175 final long t0 = System.currentTimeMillis();
177 boolean triggerSnap =
false;
178 while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
180 t1 = System.currentTimeMillis();
189 Assert.assertNotNull(frame);
190 Assert.assertNotNull(glJPanel);
191 Assert.assertNotNull(animator);
195 Assert.assertEquals(
false, animator.isAnimating());
197 SwingUtilities.invokeAndWait(
new Runnable() {
199 frame.setVisible(
false);
200 frame.getContentPane().remove(glJPanel);
201 frame.remove(glJPanel);
209 throws AWTException, InterruptedException, InvocationTargetException
216 if(shallUsePBuffer) {
227 throws AWTException, InterruptedException, InvocationTargetException
240 throws AWTException, InterruptedException, InvocationTargetException
252 throws AWTException, InterruptedException, InvocationTargetException
266 throws AWTException, InterruptedException, InvocationTargetException
278 throws AWTException, InterruptedException, InvocationTargetException
290 static long duration = 500;
292 public static void main(
final String args[]) {
293 for(
int i=0; i<args.length; i++) {
294 if(args[i].equals(
"-time")) {
297 }
else if(args[i].equals(
"-vsync")) {
300 }
else if(args[i].equals(
"-msaa")) {
302 }
else if(args[i].equals(
"-noanim")) {
304 }
else if(args[i].equals(
"-pbuffer")) {
305 shallUsePBuffer =
true;
306 }
else if(args[i].equals(
"-bitmap")) {
307 shallUseBitmap =
true;
308 }
else if(args[i].equals(
"-manual")) {
312 System.err.println(
"swapInterval "+swapInterval);
313 System.err.println(
"useMSAA "+useMSAA);
314 System.err.println(
"useAnimator "+useAnimator);
315 System.err.println(
"shallUsePBuffer "+shallUsePBuffer);
316 System.err.println(
"shallUseBitmap "+shallUseBitmap);
317 System.err.println(
"manualTest "+manualTest);
void setBitmap(final boolean enable)
Requesting offscreen bitmap mode.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
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 setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setFBO(final boolean enable)
Requesting offscreen FBO mode.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
GLCapabilities copyFrom(final CapabilitiesImmutable source)
Copies all CapabilitiesImmutable values from source into this instance.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
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.
A lightweight Swing component which provides OpenGL rendering support.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
void destroy()
Just an alias for removeNotify.
final void setRequestedGLCapabilities(final GLCapabilitiesImmutable caps)
Set a new requested GLCapabilitiesImmutable for this GLJPanel allowing reconfiguration.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
static void releaseClass()
void test01_DefaultNorm()
void test03_PbufferNorm()
static void main(final String args[])
void runTestGL(final GLCapabilities caps)
void test02_DefaultMsaa()
void test04_PbufferMsaa()
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
final void setUpdateFPSFrames(final int frames, final PrintStream out)
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this FPSAnimator.
boolean isBitmap()
Returns whether bitmap offscreen mode is requested, available or chosen.
Specifies an immutable set of OpenGL capabilities.
boolean getSampleBuffers()
Returns whether sample buffers for full-scene antialiasing (FSAA) should be allocated for this drawab...
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.