1package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
4import java.lang.reflect.InvocationTargetException;
6import javax.swing.SwingUtilities;
8import org.junit.Assert;
9import org.junit.Assume;
10import org.junit.FixMethodOrder;
12import org.junit.runners.MethodSorters;
14import com.jogamp.nativewindow.util.DimensionImmutable;
15import com.jogamp.newt.awt.NewtCanvasAWT;
16import com.jogamp.newt.opengl.GLWindow;
17import com.jogamp.opengl.GL;
18import com.jogamp.opengl.GL2;
19import com.jogamp.opengl.GL2ES1;
20import com.jogamp.opengl.GL2ES3;
21import com.jogamp.opengl.GLAutoDrawable;
22import com.jogamp.opengl.GLCapabilities;
23import com.jogamp.opengl.GLEventListener;
24import com.jogamp.opengl.GLProfile;
25import com.jogamp.opengl.fixedfunc.GLLightingFunc;
26import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
27import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
28import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
29import com.jogamp.opengl.test.junit.util.MiscUtils;
30import com.jogamp.opengl.test.junit.util.NewtTestUtil;
31import com.jogamp.opengl.test.junit.util.UITestCase;
32import com.jogamp.opengl.util.Animator;
38@FixMethodOrder(MethodSorters.NAME_ASCENDING)
42 final int[] exp_gl_viewport = { -1, -1, -1, -1 };
43 final int[] has_gl_viewport = { -1, -1, -1, -1 };
44 private float rotateT = 0.0f;
87 public void reshape(
final GLAutoDrawable glDrawable,
final int x,
final int y,
final int width,
final int height)
90 exp_gl_viewport[0] = x;
91 exp_gl_viewport[1] = y;
92 exp_gl_viewport[2] = width;
93 exp_gl_viewport[3] = height;
96 ", reshape "+x+
"/"+y+
" "+width+
"x"+height);
97 System.err.println(
"GLEL reshape: Viewport "+has_gl_viewport[0]+
"/"+has_gl_viewport[1]+
", "+has_gl_viewport[2]+
"x"+has_gl_viewport[3]);
99 final float aspect = (float) width / (
float) height;
102 final float fh = 0.5f;
103 final float fw = fh * aspect;
104 gl.
glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
114 static long duration = 500;
116 static void setFrameSize(
final Frame frame,
final boolean frameLayout,
final int newWith,
final int newHeight) {
118 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
121 final java.awt.Dimension d =
new java.awt.Dimension(newWith, newHeight);
127 }
catch(
final Throwable throwable ) {
128 throwable.printStackTrace();
129 Assume.assumeNoException( throwable );
134 public void test01() throws InterruptedException, InvocationTargetException {
149 public void windowResized(final com.jogamp.newt.event.WindowEvent e) {
150 System.err.println(
"window resized: "+glWindow.getX()+
"/"+glWindow.getY()+
" "+glWindow.getSurfaceWidth()+
"x"+glWindow.getSurfaceHeight());
153 public void windowMoved(
final com.jogamp.newt.event.WindowEvent e) {
154 System.err.println(
"window moved: "+glWindow.getX()+
"/"+glWindow.getY()+
" "+glWindow.getSurfaceWidth()+
"x"+glWindow.getSurfaceHeight());
159 final Frame frame =
new Frame(getClass().getSimpleName());
161 final boolean[] isClosed = {
false };
164 frame.setSize(640, 480);
166 frame.addWindowListener(
new java.awt.event.WindowAdapter() {
168 public void windowClosing(final java.awt.event.WindowEvent e)
176 SwingUtilities.invokeAndWait(
new Runnable() {
180 frame.setVisible(
true);
183 Assert.assertEquals(
true, AWTRobotUtil.waitForVisible(frame,
true,
null));
184 Assert.assertEquals(
true, NewtTestUtil.waitForRealized(glWindow,
true,
null));
187 Assert.assertTrue(animator.isAnimating());
190 System.err.println(
"NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
191 System.err.println(
"GL chosen: "+glWindow.getChosenCapabilities());
192 System.err.println(
"window pos/siz: "+glWindow.getX()+
"/"+glWindow.getY()+
" "+glWindow.getSurfaceWidth()+
"x"+glWindow.getSurfaceHeight()+
", "+glWindow.getInsets());
193 System.err.println(
"XXXX");
195 canvas.requestFocus();
196 snap.setMakeSnapshot();
199 setFrameSize(frame,
false , 800, 600);
200 snap.setMakeSnapshot();
202 snap.setMakeSnapshot();
204 final long t0 = System.currentTimeMillis();
206 while(!isClosed[0] && t1-t0<duration) {
208 t1 = System.currentTimeMillis();
213 Assert.assertFalse(animator.isAnimating());
214 Assert.assertFalse(animator.
isStarted());
215 SwingUtilities.invokeAndWait(
new Runnable() {
222 Assert.assertEquals(
true, NewtTestUtil.waitForRealized(glWindow,
false,
null));
226 public static void main(
final String[] args)
228 for(
int i=0; i<args.length; i++) {
229 if(args[i].equals(
"-time")) {
234 System.err.println(
"duration "+duration);
AWT Canvas containing a NEWT Window using native parenting.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
void display(final GLAutoDrawable gLDrawable)
Called by the drawable to initiate OpenGL rendering by the client.
void dispose(final GLAutoDrawable gLDrawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void init(final GLAutoDrawable glDrawable)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(final GLAutoDrawable glDrawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
Self-contained example (within a single class only to keep it simple) displaying a rotating quad.
static void main(final String[] args)
static long atol(final String str, final long def)
void setPostSNDetail(final String v)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
static final int GL_PERSPECTIVE_CORRECTION_HINT
GL_VERSION_ES_1_0, GL_VERSION_1_0 Define "GL_PERSPECTIVE_CORRECTION_HINT" with expression '0x0C50',...
static final int GL_QUADS
GL_ES_VERSION_3_2, GL_VERSION_1_1, GL_VERSION_1_0, GL_OES_tessellation_shader, GL_EXT_tessellation_sh...
void glBegin(int mode)
Entry point to C language function: void {@native glBegin}(GLenum mode) Part of GL_VERSION_1_0
void glVertex3f(float x, float y, float z)
Entry point to C language function: void {@native glVertex3f}(GLfloat x, GLfloat y,...
void glEnd()
Entry point to C language function: void {@native glEnd}() Part of GL_VERSION_1_0
void glColor3f(float red, float green, float blue)
Entry point to C language function: void {@native glColor3f}(GLfloat red, GLfloat green,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void glClearDepth(double depth)
Aliased entrypoint of void {@native glClearDepth}(GLclampd depth); and void {@native glClearDepthf...
GL2 getGL2()
Casts this object to the GL2 interface.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glGetIntegerv(int pname, IntBuffer data)
Entry point to C language function: void {@native glGetIntegerv}(GLenum pname, GLint * data) Part ...
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glHint(int target, int mode)
Entry point to C language function: void {@native glHint}(GLenum target, GLenum mode) Part of GL_E...
static final int GL_NICEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NICEST" with expressi...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
void glDepthFunc(int func)
Entry point to C language function: void {@native glDepthFunc}(GLenum func) Part of GL_ES_VERSION_...
static final int GL_LEQUAL
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LEQUAL" with expressi...
static final int GL_VIEWPORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VIEWPORT" with expres...
static final int GL_SMOOTH
void glShadeModel(int mode)
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar)
Multiply the current matrix with the frustum matrix.
void glTranslatef(float x, float y, float z)
Translate the current matrix.
void glRotatef(float angle, float x, float y, float z)
Rotate the current matrix.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.