summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-09-20 16:48:18 +0200
committerSven Gothel <[email protected]>2014-09-20 16:48:18 +0200
commit7321a2ea8964305f89f723f5c8034040da29765d (patch)
tree52958a79261cf83fb25d19e6784dda1b0d0d37e5 /src/test/com/jogamp/opengl
parentc68e7f9b56f08341ec4977337e3c07384c3782fb (diff)
Add GLJPanelsAndGLCanvasDemoGL2Applet: Simple applet test for GLJPanel/GL2 testing (offscreen, ..); Clean up GL2 Gears and Teapot state enable/disable
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java76
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java62
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelAndGLCanvasApplet.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/GLJPanelsAndGLCanvasDemoGL2Applet.java180
4 files changed, 271 insertions, 52 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java
index deee8a7aa..9f97b4a21 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java
@@ -117,6 +117,36 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
}
}
+ boolean enableCullFace = false;
+
+ private void enableStates(final GL gl, final boolean enable) {
+ final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers();
+ if( enable ) {
+ if( enableCullFace ) {
+ gl.glEnable(GL.GL_CULL_FACE);
+ }
+ gl.glEnable(GLLightingFunc.GL_LIGHTING);
+ gl.glEnable(GLLightingFunc.GL_LIGHT0);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LESS); // default
+ gl.glEnable(GLLightingFunc.GL_NORMALIZE);
+ if( msaa ) {
+ gl.glEnable(GL.GL_MULTISAMPLE);
+ }
+ } else {
+ if( enableCullFace ) {
+ gl.glDisable(GL.GL_CULL_FACE);
+ }
+ gl.glDisable(GLLightingFunc.GL_LIGHTING);
+ gl.glDisable(GLLightingFunc.GL_LIGHT0);
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ gl.glDisable(GLLightingFunc.GL_NORMALIZE);
+ if( msaa ) {
+ gl.glDisable(GL.GL_MULTISAMPLE);
+ }
+ }
+ }
+
public void init(final GL2 gl) {
final float lightPos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
final float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
@@ -134,11 +164,11 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, lightPos, 0);
if( ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) ) {
// Only possible if we do not flip the projection matrix
- gl.glEnable(GL.GL_CULL_FACE);
+ enableCullFace = true;
+ } else {
+ enableCullFace = false;
}
- gl.glEnable(GLLightingFunc.GL_LIGHTING);
- gl.glEnable(GLLightingFunc.GL_LIGHT0);
- gl.glEnable(GL.GL_DEPTH_TEST);
+ enableStates(gl, true);
/* make the gears */
if(0>=gear1) {
@@ -174,7 +204,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
System.err.println("gear3 list reused: "+gear3);
}
- gl.glEnable(GLLightingFunc.GL_NORMALIZE);
+ enableStates(gl, false);
}
@Override
@@ -196,12 +226,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
}
public void reshape(final GL2 gl, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight) {
- final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers();
- System.err.println(Thread.currentThread()+" Gears.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", msaa "+msaa+", tileRendererInUse "+tileRendererInUse);
-
- if( msaa ) {
- gl.glEnable(GL.GL_MULTISAMPLE);
- }
+ System.err.println(Thread.currentThread()+" Gears.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", tileRendererInUse "+tileRendererInUse);
// compute projection parameters 'normal'
float left, right, bottom, top;
@@ -244,10 +269,6 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -40.0f);
-
- if( msaa ) {
- gl.glDisable(GL.GL_MULTISAMPLE);
- }
}
@Override
@@ -268,11 +289,8 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
public void display(final GLAutoDrawable drawable) {
// Get the GL corresponding to the drawable we are animating
final GL2 gl = drawable.getGL().getGL2();
- final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers();
- if( msaa ) {
- gl.glEnable(GL.GL_MULTISAMPLE);
- }
+ enableStates(gl, true);
if( null == tileRendererInUse ) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -291,15 +309,13 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
displayImpl(gl);
- if( msaa ) {
- gl.glDisable(GL.GL_MULTISAMPLE);
- }
+
+ enableStates(gl, false);
}
+
public void display(final GL2 gl) {
- final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers();
- if( msaa ) {
- gl.glEnable(GL.GL_MULTISAMPLE);
- }
+ enableStates(gl, true);
+
if( null == tileRendererInUse ) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
} else {
@@ -307,10 +323,10 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
}
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
displayImpl(gl);
- if( msaa ) {
- gl.glDisable(GL.GL_MULTISAMPLE);
- }
+
+ enableStates(gl, false);
}
+
private void displayImpl(final GL2 gl) {
if( doRotate ) {
// Turn the gears' teeth
@@ -451,7 +467,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f);
gl.glEnd();
- gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
+ gl.glShadeModel(GLLightingFunc.GL_SMOOTH); // default
/* draw inside radius cylinder */
gl.glBegin(GL2.GL_QUAD_STRIP);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java
index d29688b96..96d6fdba0 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Teapot.java
@@ -24,10 +24,46 @@ public class Teapot implements GLEventListener {
private GLUT glut;
/* glTexGen stuff: */
- private final float sgenparams[] = { 1.0f, 1.0f, 1.0f, 0.0f };
+ // private final float sgenparams[] = { 1.0f, 1.0f, 1.0f, 0.0f };
private Texture tex = null;
+ private void enableStates(final GL2 gl, final boolean enable) {
+ if( enable ) {
+ if( null != tex ) {
+ tex.bind(gl);
+ }
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LESS); // default
+ // gl.glEnable(GL2.GL_TEXTURE_GEN_S);
+ // gl.glEnable(GL2.GL_TEXTURE_1D);
+ gl.glEnable(GL.GL_TEXTURE_2D);
+ gl.glEnable(GL.GL_CULL_FACE);
+ gl.glEnable(GLLightingFunc.GL_LIGHTING);
+ gl.glEnable(GLLightingFunc.GL_LIGHT0);
+ gl.glEnable(GL2.GL_AUTO_NORMAL);
+ gl.glEnable(GLLightingFunc.GL_NORMALIZE);
+ gl.glFrontFace(GL.GL_CW);
+ gl.glCullFace(GL.GL_BACK); // default
+ gl.glMaterialf(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, 64.0f);
+ gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
+ } else {
+ if( null != tex ) {
+ gl.glBindTexture(tex.getTarget(), 0);
+ }
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ // gl.glDisable(GL2.GL_TEXTURE_GEN_S);
+ // gl.glDisable(GL2.GL_TEXTURE_1D);
+ gl.glDisable(GL.GL_TEXTURE_2D);
+ gl.glDisable(GL.GL_CULL_FACE);
+ gl.glDisable(GLLightingFunc.GL_LIGHTING);
+ gl.glDisable(GLLightingFunc.GL_LIGHT0);
+ gl.glDisable(GL2.GL_AUTO_NORMAL);
+ gl.glDisable(GLLightingFunc.GL_NORMALIZE);
+ gl.glFrontFace(GL.GL_CCW); // default
+ }
+ }
+
@Override
public void init(final GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
@@ -41,7 +77,7 @@ public class Teapot implements GLEventListener {
} catch (final Exception e) {
e.printStackTrace();
}
- tex.bind(gl);
+ // tex.bind(gl);
// uncomment this and comment the above to see a working texture
// makeStripeImage();
@@ -57,24 +93,10 @@ public class Teapot implements GLEventListener {
// gl.glTexImage1D(GL2.GL_TEXTURE_1D, 0, 3, stripeImageWidth, 0,
// GL.GL_RGB, GL.GL_UNSIGNED_BYTE, stripeImageBuf);
- gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
+ // gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
// gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, GL2.GL_OBJECT_LINEAR);
// gl.glTexGenfv(GL2.GL_S, GL2.GL_OBJECT_PLANE, sgenparams, 0);
-
- gl.glEnable(GL.GL_DEPTH_TEST);
- gl.glDepthFunc(GL.GL_LESS);
- // gl.glEnable(GL2.GL_TEXTURE_GEN_S);
- // gl.glEnable(GL2.GL_TEXTURE_1D);
- gl.glEnable(GL.GL_TEXTURE_2D);
- gl.glEnable(GL.GL_CULL_FACE);
- gl.glEnable(GLLightingFunc.GL_LIGHTING);
- gl.glEnable(GLLightingFunc.GL_LIGHT0);
- gl.glEnable(GL2.GL_AUTO_NORMAL);
- gl.glEnable(GLLightingFunc.GL_NORMALIZE);
- gl.glFrontFace(GL.GL_CW);
- gl.glCullFace(GL.GL_BACK);
- gl.glMaterialf(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, 64.0f);
}
float angleZ = 0.0f;
@@ -85,8 +107,7 @@ public class Teapot implements GLEventListener {
public void display(final GLAutoDrawable gLDrawable) {
final GL2 gl = gLDrawable.getGL().getGL2();
- tex.bind(gl);
- gl.glEnable(GL.GL_TEXTURE_2D);
+ enableStates(gl, true);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPushMatrix();
@@ -101,13 +122,14 @@ public class Teapot implements GLEventListener {
rotDir = +1.0f;
}
angleZ += rotIncr * rotDir;
+
+ enableStates(gl, false);
}
@Override
public void reshape(final GLAutoDrawable gLDrawable, final int x, final int y, final int w, final int h) {
final GL2 gl = gLDrawable.getGL().getGL2();
- gl.glViewport(0, 0, w, h);
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
if (w <= h) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelAndGLCanvasApplet.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelAndGLCanvasApplet.java
index b6a1c3cee..a153fc7ae 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelAndGLCanvasApplet.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/Bug818GLJPanelAndGLCanvasApplet.java
@@ -52,6 +52,7 @@ import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
+import javax.swing.SwingConstants;
import com.jogamp.common.util.VersionUtil;
import com.jogamp.opengl.JoglVersion;
@@ -123,8 +124,8 @@ public class Bug818GLJPanelAndGLCanvasApplet extends JApplet {
panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
System.err.println("Post Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
setContentPane(panel);
- panel.add(new JLabel("GLJPanel"));
- panel.add(new JLabel("GLCanvas"));
+ panel.add(new JLabel("GLJPanel", SwingConstants.CENTER));
+ panel.add(new JLabel("GLCanvas", SwingConstants.CENTER));
final GLJPanel gljPanel = new GLJPanel();
gljPanel.addGLEventListener(new JOGLQuad(false));
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/GLJPanelsAndGLCanvasDemoGL2Applet.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/GLJPanelsAndGLCanvasDemoGL2Applet.java
new file mode 100644
index 000000000..fcff9e56b
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/GLJPanelsAndGLCanvasDemoGL2Applet.java
@@ -0,0 +1,180 @@
+/**
+ * Copyright 2013 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt;
+
+import java.awt.ComponentOrientation;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.media.opengl.awt.GLCanvas;
+import javax.media.opengl.awt.GLJPanel;
+import javax.swing.JApplet;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JFrame;
+import javax.swing.SwingConstants;
+
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
+import com.jogamp.opengl.test.junit.jogl.demos.gl2.Teapot;
+import com.jogamp.opengl.util.Animator;
+
+/**
+ */
+public class GLJPanelsAndGLCanvasDemoGL2Applet extends JApplet {
+
+ private static final long serialVersionUID = 1L;
+
+ private Animator[] animator;
+
+ public static JFrame frame;
+ public static JPanel appletHolder;
+ public static boolean isApplet = true;
+
+ static public void main(final String args[]) {
+ isApplet = false;
+
+ final JApplet myApplet = new GLJPanelsAndGLCanvasDemoGL2Applet();
+
+ appletHolder = new JPanel();
+
+ frame = new JFrame("Bug818GLJPanelApplet");
+ frame.getContentPane().add(myApplet);
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(final WindowEvent e) {
+ System.exit(0);
+ }
+ });
+
+ try {
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ myApplet.init();
+ frame.validate();
+ frame.pack();
+ frame.setVisible(true);
+ } } );
+ } catch( final Throwable throwable ) {
+ throwable.printStackTrace();
+ }
+
+ myApplet.start();
+ }
+
+
+ @Override
+ public void init() {
+
+ final JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(3, 2));
+ System.err.println("Pre Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
+ panel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+ System.err.println("Post Orientation L2R: "+panel.getComponentOrientation().isLeftToRight());
+ setContentPane(panel);
+
+ animator = new Animator[3*2];
+ int animIdx = 0;
+
+ panel.add(new JLabel("GLJPanel Auto V-Flip", SwingConstants.CENTER));
+ {
+ {
+ final GLJPanel gljPanel = new GLJPanel();
+ gljPanel.addGLEventListener(new Teapot());
+ animator[animIdx++] = new Animator(gljPanel);
+ gljPanel.setPreferredSize(new Dimension(300, 300));
+ panel.add(gljPanel);
+ }
+ {
+ final GLJPanel gljPanel = new GLJPanel();
+ gljPanel.addGLEventListener(new Gears(0));
+ animator[animIdx++] = new Animator(gljPanel);
+ gljPanel.setPreferredSize(new Dimension(300, 300));
+ panel.add(gljPanel);
+ }
+ }
+ panel.add(new JLabel("GLJPanel User V-Flip", SwingConstants.CENTER));
+ {
+ {
+ final GLJPanel gljPanel = new GLJPanel();
+ gljPanel.setSkipGLOrientationVerticalFlip(true);
+ gljPanel.addGLEventListener(new Teapot());
+ animator[animIdx++] = new Animator(gljPanel);
+ gljPanel.setPreferredSize(new Dimension(300, 300));
+ panel.add(gljPanel);
+ }
+ {
+ final GLJPanel gljPanel = new GLJPanel();
+ gljPanel.setSkipGLOrientationVerticalFlip(true);
+ gljPanel.addGLEventListener(new Gears(0));
+ animator[animIdx++] = new Animator(gljPanel);
+ gljPanel.setPreferredSize(new Dimension(300, 300));
+ panel.add(gljPanel);
+ }
+ }
+
+ panel.add(new JLabel("GLCanvas", SwingConstants.CENTER));
+ {
+ {
+ final GLCanvas glCanvas = new GLCanvas();
+ glCanvas.addGLEventListener(new Teapot());
+ animator[animIdx++] = new Animator(glCanvas);
+ glCanvas.setPreferredSize(new Dimension(300, 300));
+ panel.add(glCanvas);
+ }
+ {
+ final GLCanvas glCanvas = new GLCanvas();
+ glCanvas.addGLEventListener(new Gears(1));
+ animator[animIdx++] = new Animator(glCanvas);
+ glCanvas.setPreferredSize(new Dimension(300, 300));
+ panel.add(glCanvas);
+ }
+ }
+ }
+
+ @Override
+ public void start() {
+ for(int i=0; i<animator.length; i++) {
+ animator[i].start();
+ animator[i].setUpdateFPSFrames(60, System.err);
+ }
+ }
+
+ @Override
+ public void stop() {
+ for(int i=0; i<animator.length; i++) {
+ animator[i].stop();
+ }
+ }
+
+ @Override
+ public void destroy() {}
+}
+