JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTeapotNEWT.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.newt;
30
31import com.jogamp.newt.opengl.GLWindow;
32import com.jogamp.opengl.test.junit.util.UITestCase;
33import com.jogamp.opengl.test.junit.util.QuitAdapter;
34
35import com.jogamp.opengl.util.Animator;
36
37import com.jogamp.opengl.test.junit.jogl.demos.gl2.Teapot;
38
39import com.jogamp.opengl.GLCapabilities;
40import com.jogamp.opengl.GLProfile;
41
42import org.junit.Assert;
43import org.junit.BeforeClass;
44import org.junit.AfterClass;
45import org.junit.Test;
46import org.junit.FixMethodOrder;
47import org.junit.runners.MethodSorters;
48
49@FixMethodOrder(MethodSorters.NAME_ASCENDING)
50public class TestTeapotNEWT extends UITestCase {
51 static GLProfile glp;
52 static int width, height;
53
54 @BeforeClass
55 public static void initClass() {
58 Assert.assertNotNull(glp);
59 width = 640;
60 height = 480;
61 } else {
62 setTestSupported(false);
63 }
64 }
65
66 @AfterClass
67 public static void releaseClass() {
68 }
69
70 protected void runTestGL(final GLCapabilities caps, final boolean withAnimator) throws InterruptedException {
71 final GLWindow glWindow = GLWindow.create(caps);
72
73 glWindow.setTitle("Teapot NEWT Test");
74 final Teapot demo = new Teapot();
75 if( !withAnimator ) {
76 demo.rotIncr *= 10f;
77 }
78 glWindow.addGLEventListener(demo);
80 glWindow.addGLEventListener(snap);
81
82 final Animator animator = withAnimator ? new Animator(glWindow) : null;
83 final QuitAdapter quitAdapter = new QuitAdapter();
84
85 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
86 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
87 glWindow.addKeyListener(quitAdapter);
88 glWindow.addWindowListener(quitAdapter);
89
90 glWindow.setSize(width, height);
91 glWindow.setVisible(true);
92 if( withAnimator ) {
93 animator.setUpdateFPSFrames(60, System.err);
94 animator.start();
95 }
96
97 final long t0 = System.currentTimeMillis();
98 long t1 = t0;
99 int snaps=3;
100 while(!quitAdapter.shouldQuit() && t1-t0<duration) {
101 Thread.sleep(100);
102 t1 = System.currentTimeMillis();
103 if( snaps-- > 0 ) {
104 snap.setMakeSnapshot();
105 }
106 if( !withAnimator ) {
107 glWindow.display();
108 }
109 }
110
111 if( withAnimator ) {
112 animator.stop();
113 }
114 glWindow.destroy();
115 }
116
117 @Test
118 public void test01_DefCaps_Anim() throws InterruptedException {
120 runTestGL(caps, true);
121 }
122
123 @Test
124 public void test02_DefCaps_NoAnim() throws InterruptedException {
126 runTestGL(caps, false);
127 }
128
129 @Test
130 public void test12_FBOCaps_NoAnim() throws InterruptedException {
132 caps.setHardwareAccelerated(true);
133 caps.setDoubleBuffered(true);
134 caps.setAlphaBits(8);
135 caps.setDepthBits(8);
136 caps.setNumSamples(0);
137 caps.setSampleBuffers(false);
138 caps.setStencilBits(0);
139 caps.setRedBits(8);
140 caps.setBlueBits(8);
141 caps.setGreenBits(8);
142
143 // caps.setPBuffer(true);
144 caps.setFBO(true);
145
146 runTestGL(caps, false);
147 }
148
149 static long duration = 500; // ms
150
151 public static void main(final String args[]) {
152 for(int i=0; i<args.length; i++) {
153 if(args[i].equals("-time")) {
154 i++;
155 try {
156 duration = Integer.parseInt(args[i]);
157 } catch (final Exception ex) { ex.printStackTrace(); }
158 }
159 }
160 org.junit.runner.JUnitCore.main(TestTeapotNEWT.class.getName());
161 }
162}
void setRedBits(final int redBits)
Sets the number of bits requested for the color buffer's red component.
void setGreenBits(final int greenBits)
Sets the number of bits requested for the color buffer's green component.
void setBlueBits(final int blueBits)
Sets the number of bits requested for the color buffer's blue component.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setHardwareAccelerated(final boolean enable)
Enables or disables hardware acceleration.
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.
void setSampleBuffers(final boolean enable)
Defaults to false.
void setDepthBits(final int depthBits)
Sets the number of bits requested for the depth buffer.
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 getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
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
Adapted from http://www.java-tips.org/other-api-tips/jogl/how-to-draw-a-texture-mapped-teapot-with-au...
Definition: Teapot.java:22
void runTestGL(final GLCapabilities caps, final boolean withAnimator)
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 addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.