aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-12-10 21:24:17 +0100
committerSven Gothel <[email protected]>2013-12-10 21:24:17 +0100
commit990b25adf6e0b6ab5c79d8ca43bc327fb93a755e (patch)
treec70a6a86ab219bdc1fd823f4193013eb4d10730a /src/test
parentab9076c83cc3b2e7800eaf0a19febe786458146d (diff)
Bug 904: 'User Vertical Flip' for GLJPanel shall be performed via PROJECTION matrix scaling instead of MODELVIEW rotation ...
'User Vertical Flip' for GLJPanel shall be performed via PROJECTION matrix scaling instead of MODELVIEW rotation to simplify workflow, and to remove artifacts w/ tiled printing.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java53
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java29
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java69
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java123
4 files changed, 155 insertions, 119 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java
index 811e91886..5891bce0d 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/RedSquareES1.java
@@ -23,10 +23,11 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
private boolean debug = false ;
private boolean trace = false ;
private int swapInterval = 0;
- private float aspect = 1.0f;
+ private final float aspect = 1.0f;
private boolean doRotate = true;
private TileRendererBase tileRendererInUse = null;
private boolean doRotateBeforePrinting;
+ private boolean flipVerticalInGLOrientation = false;
long startTime = 0;
long curTime = 0;
@@ -38,17 +39,17 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
public RedSquareES1() {
this.swapInterval = 1;
}
-
+
@Override
public void addTileRendererNotify(TileRendererBase tr) {
tileRendererInUse = tr;
doRotateBeforePrinting = doRotate;
- setDoRotation(false);
+ setDoRotation(false);
}
@Override
public void removeTileRendererNotify(TileRendererBase tr) {
tileRendererInUse = null;
- setDoRotation(doRotateBeforePrinting);
+ setDoRotation(doRotateBeforePrinting);
}
@Override
public void startTileRendering(TileRendererBase tr) {
@@ -58,7 +59,7 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
public void endTileRendering(TileRendererBase tr) {
System.err.println("RedSquareES1.endTileRendering: "+tr);
}
-
+
public void setDoRotation(boolean rotate) { this.doRotate = rotate; }
public void setForceFFPEmu(boolean forceFFPEmu, boolean verboseFFPEmu, boolean debugFFPEmu, boolean traceFFPEmu) {
this.forceFFPEmu = forceFFPEmu;
@@ -66,7 +67,8 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
this.debugFFPEmu = debugFFPEmu;
this.traceFFPEmu = traceFFPEmu;
}
-
+ public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; }
+
// FIXME: we must add storage of the pointers in the GL state to
// the GLImpl classes. The need for this can be seen by making
// these variables method local instead of instance members. The
@@ -93,12 +95,12 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
trace = false;
}
GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl, ShaderSelectionMode.AUTO, null, forceFFPEmu, verboseFFPEmu);
-
+
if(debug) {
try {
// Debug ..
gl = (GL2ES1) gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", GL2ES1.class, gl, null) );
- } catch (Exception e) {e.printStackTrace();}
+ } catch (Exception e) {e.printStackTrace();}
}
if(trace) {
try {
@@ -139,34 +141,37 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
@Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
final GL2ES1 gl = glad.getGL().getGL2ES1();
- if(-1 != swapInterval) {
+ if(-1 != swapInterval) {
gl.setSwapInterval(swapInterval);
}
reshapeImpl(gl, x, y, width, height, width, height);
}
-
+
@Override
public void reshapeTile(TileRendererBase tr,
- int tileX, int tileY, int tileWidth, int tileHeight,
+ int tileX, int tileY, int tileWidth, int tileHeight,
int imageWidth, int imageHeight) {
final GL2ES1 gl = tr.getAttachedDrawable().getGL().getGL2ES1();
gl.setSwapInterval(0);
reshapeImpl(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight);
}
-
+
void reshapeImpl(GL2ES1 gl, int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight) {
System.err.println(Thread.currentThread()+" RedSquareES1.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", tileRendererInUse "+tileRendererInUse);
-
+
// Set location in front of camera
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
-
+ if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
+ gl.glScalef(1f, -1f, 1f);
+ }
+
// compute projection parameters 'normal' perspective
final float fovy=45f;
final float aspect2 = ( (float) imageWidth / (float) imageHeight ) / aspect;
final float zNear=1f;
final float zFar=100f;
-
+
// compute projection parameters 'normal' frustum
final float top=(float)Math.tan(fovy*((float)Math.PI)/360.0f)*zNear;
final float bottom=-1.0f*top;
@@ -174,18 +179,22 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
final float right=aspect2*top;
final float w = right - left;
final float h = top - bottom;
-
+
// compute projection parameters 'tiled'
final float l = left + tileX * w / imageWidth;
final float r = l + tileWidth * w / imageWidth;
final float b = bottom + tileY * h / imageHeight;
final float t = b + tileHeight * h / imageHeight;
-
+
gl.glFrustumf(l, r, b, t, zNear, zFar);
// gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
System.err.println(Thread.currentThread()+" RedSquareES1.reshape FIN");
}
-
+
@Override
public void display(GLAutoDrawable drawable) {
curTime = System.currentTimeMillis();
@@ -201,11 +210,9 @@ public class RedSquareES1 implements GLEventListener, TileRendererBase.TileRende
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -10);
- if(doRotate) {
- float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f;
- gl.glRotatef(ang, 0, 0, 1);
- gl.glRotatef(ang, 0, 1, 0);
- }
+ float ang = doRotate ? ((curTime - startTime) * 360.0f) / 4000.0f : 1f;
+ gl.glRotatef(ang, 0, 0, 1);
+ gl.glRotatef(ang, 0, 1, 0);
// Draw a square
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index ff5de7cb0..d85d38618 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -356,8 +356,6 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL
}
st.useProgram(gl, true);
- pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
// compute projection parameters 'normal'
float left, right, bottom, top;
@@ -386,17 +384,19 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL
final float _w = r - l;
final float _h = t - b;
if(verbose) {
- System.err.println(">> angle "+sid()+" "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h);
+ System.err.println(">> GearsES2 "+sid()+", angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h+", v-flip "+flipVerticalInGLOrientation);
}
+ pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
+ pmvMatrix.glScalef(1f, -1f, 1f);
+ }
pmvMatrix.glFrustumf(l, r, b, t, 5.0f, 200.0f);
pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
pmvMatrix.glLoadIdentity();
pmvMatrix.glTranslatef(0.0f, 0.0f, -40.0f);
- if(flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
- pmvMatrix.glRotatef(180f, 1.0f, 0.0f, 0.0f);
- }
st.uniform(gl, pmvMatrixUniform);
st.useProgram(gl, false);
@@ -490,15 +490,18 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL
return;
}
- gl.glEnable(GL.GL_CULL_FACE);
+ // Only possible if we do not flip the projection matrix
+ final boolean enableCullFace = ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() );
+ if( enableCullFace ) {
+ gl.glEnable(GL.GL_CULL_FACE);
+ }
st.useProgram(gl, true);
pmvMatrix.glPushMatrix();
pmvMatrix.glTranslatef(panX, panY, panZ);
- final float flipVF = ( flipVerticalInGLOrientation && drawable.isGLOriented() ) ? -1f : 1f;
- pmvMatrix.glRotatef(flipVF*view_rotx, 1.0f, 0.0f, 0.0f);
- pmvMatrix.glRotatef(flipVF*view_roty, 0.0f, 1.0f, 0.0f);
- pmvMatrix.glRotatef(flipVF*view_rotz, 0.0f, 0.0f, 1.0f);
+ pmvMatrix.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
+ pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
+ pmvMatrix.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
gear1.draw(gl, -3.0f, -2.0f, 1f * angle - 0f);
gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f);
@@ -506,7 +509,9 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererL
pmvMatrix.glPopMatrix();
st.useProgram(gl, false);
- gl.glDisable(GL.GL_CULL_FACE);
+ if( enableCullFace ) {
+ gl.glDisable(GL.GL_CULL_FACE);
+ }
}
@Override
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
index 3a9cf8f98..46e39bebf 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
@@ -3,14 +3,14 @@
*
* 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
@@ -20,12 +20,12 @@
* 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.es2.awt;
import java.awt.AWTException;
@@ -63,12 +63,14 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
static Dimension wsize, rwsize=null;
static boolean forceES2 = false;
static boolean forceGL3 = false;
+ static boolean forceGLFFP = false;
static boolean shallUsePBuffer = false;
static boolean shallUseBitmap = false;
static boolean useMSAA = false;
static int swapInterval = 0;
static boolean useAnimator = true;
static boolean manualTest = false;
+ static boolean skipGLOrientationVerticalFlip = false;
@BeforeClass
public static void initClass() {
@@ -93,9 +95,9 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
} catch( Throwable throwable ) {
throwable.printStackTrace();
Assume.assumeNoException( throwable );
- }
+ }
}
-
+
protected void runTestGL(GLCapabilities caps)
throws AWTException, InterruptedException, InvocationTargetException
{
@@ -104,13 +106,18 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
final GLJPanel glJPanel = new GLJPanel(caps);
Assert.assertNotNull(glJPanel);
+ glJPanel.setSkipGLOrientationVerticalFlip(skipGLOrientationVerticalFlip);
glJPanel.setMinimumSize(wsize);
glJPanel.setPreferredSize(wsize);
glJPanel.setSize(wsize);
- if( caps.isBitmap() ) {
- glJPanel.addGLEventListener(new Gears(swapInterval));
+ if( caps.isBitmap() || caps.getGLProfile().isGL2() ) {
+ final Gears gears = new Gears(swapInterval);
+ gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
+ glJPanel.addGLEventListener(gears);
} else {
- glJPanel.addGLEventListener(new GearsES2(swapInterval));
+ final GearsES2 gears = new GearsES2(swapInterval);
+ gears.setFlipVerticalInGLOrientation(skipGLOrientationVerticalFlip);
+ glJPanel.addGLEventListener(gears);
}
final SnapshotGLEventListener snap = new SnapshotGLEventListener();
glJPanel.addGLEventListener(snap);
@@ -135,17 +142,17 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glJPanel);
new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
-
+
snap.setMakeSnapshot();
-
+
if( null != rwsize ) {
- Thread.sleep(500); // 500ms delay
+ Thread.sleep(500); // 500ms delay
setFrameSize(frame, true, rwsize);
System.err.println("window resize pos/siz: "+glJPanel.getX()+"/"+glJPanel.getY()+" "+glJPanel.getWidth()+"x"+glJPanel.getHeight());
}
-
+
snap.setMakeSnapshot();
-
+
final long t0 = System.currentTimeMillis();
long t1 = t0;
boolean triggerSnap = false;
@@ -187,6 +194,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
glp = GLProfile.get(GLProfile.GL3);
} else if(forceES2) {
glp = GLProfile.get(GLProfile.GLES2);
+ } else if(forceGLFFP) {
+ glp = GLProfile.getMaxFixedFunc(true);
} else {
glp = GLProfile.getGL2ES2();
}
@@ -216,7 +225,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
caps.setSampleBuffers(true);
runTestGL(caps);
}
-
+
@Test
public void test03_PbufferNorm()
throws AWTException, InterruptedException, InvocationTargetException
@@ -228,7 +237,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
caps.setPBuffer(true);
runTestGL(caps);
}
-
+
@Test
public void test04_PbufferMsaa()
throws AWTException, InterruptedException, InvocationTargetException
@@ -242,7 +251,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
caps.setPBuffer(true);
runTestGL(caps);
}
-
+
@Test
public void test05_BitmapNorm()
throws AWTException, InterruptedException, InvocationTargetException
@@ -254,7 +263,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
caps.setBitmap(true);
runTestGL(caps);
}
-
+
@Test
public void test06_BitmapMsaa()
throws AWTException, InterruptedException, InvocationTargetException
@@ -268,7 +277,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
caps.setBitmap(true);
runTestGL(caps);
}
-
+
@Test
public void test20_GLES2()
throws AWTException, InterruptedException, InvocationTargetException
@@ -276,7 +285,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
if( manualTest ) {
return;
}
-
+
if( !GLProfile.isAvailable(GLProfile.GLES2) ) {
System.err.println("GLES2 n/a");
return;
@@ -285,7 +294,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
final GLCapabilities caps = new GLCapabilities( glp );
runTestGL(caps);
}
-
+
@Test
public void test30_GL3()
throws AWTException, InterruptedException, InvocationTargetException
@@ -293,7 +302,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
if( manualTest ) {
return;
}
-
+
if( !GLProfile.isAvailable(GLProfile.GL3) ) {
System.err.println("GL3 n/a");
return;
@@ -302,12 +311,12 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
final GLCapabilities caps = new GLCapabilities( glp );
runTestGL(caps);
}
-
+
static long duration = 500; // ms
public static void main(String args[]) {
int w=640, h=480, rw=-1, rh=-1;
-
+
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
@@ -316,6 +325,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
forceES2 = true;
} else if(args[i].equals("-gl3")) {
forceGL3 = true;
+ } else if(args[i].equals("-glFFP")) {
+ forceGLFFP = true;
} else if(args[i].equals("-width")) {
i++;
w = MiscUtils.atoi(args[i], w);
@@ -328,6 +339,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
} else if(args[i].equals("-rheight")) {
i++;
rh = MiscUtils.atoi(args[i], rh);
+ } else if(args[i].equals("-userVFlip")) {
+ skipGLOrientationVerticalFlip = true;
} else if(args[i].equals("-vsync")) {
i++;
swapInterval = MiscUtils.atoi(args[i], swapInterval);
@@ -347,18 +360,20 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
if( 0 < rw && 0 < rh ) {
rwsize = new Dimension(rw, rh);
}
-
+
System.err.println("size "+wsize);
System.err.println("resize "+rwsize);
+ System.err.println("userVFlip "+skipGLOrientationVerticalFlip);
System.err.println("swapInterval "+swapInterval);
System.err.println("forceES2 "+forceES2);
System.err.println("forceGL3 "+forceGL3);
+ System.err.println("forceGLFFP "+forceGLFFP);
System.err.println("useMSAA "+useMSAA);
System.err.println("useAnimator "+useAnimator);
System.err.println("shallUsePBuffer "+shallUsePBuffer);
System.err.println("shallUseBitmap "+shallUseBitmap);
System.err.println("manualTest "+manualTest);
-
+
org.junit.runner.JUnitCore.main(TestGearsES2GLJPanelAWT.class.getName());
}
}
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 031d6a1c1..0d71c7ad0 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
@@ -27,17 +27,19 @@ import com.jogamp.opengl.util.TileRendererBase;
* This version is equal to Brian Paul's version 1.2 1999/10/21
*/
public class Gears implements GLEventListener, TileRendererBase.TileRendererListener {
- private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
+ private float view_rotx = 20.0f, view_roty = 30.0f;
+ private final float view_rotz = 0.0f;
private int gear1=0, gear2=0, gear3=0;
private float angle = 0.0f;
private boolean doRotate = true;
- private int swapInterval;
- private MouseListener gearsMouse = new GearsMouseAdapter();
- private KeyListener gearsKeys = new GearsKeyAdapter();
+ private final int swapInterval;
+ private final MouseListener gearsMouse = new GearsMouseAdapter();
+ private final KeyListener gearsKeys = new GearsKeyAdapter();
private TileRendererBase tileRendererInUse = null;
private boolean doRotateBeforePrinting;
private boolean verbose = true;
-
+ private boolean flipVerticalInGLOrientation = false;
+
// private boolean mouseRButtonDown = false;
private int prevMouseX, prevMouseY;
@@ -48,17 +50,17 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
public Gears() {
this.swapInterval = 1;
}
-
+
@Override
public void addTileRendererNotify(TileRendererBase tr) {
tileRendererInUse = tr;
doRotateBeforePrinting = doRotate;
- setDoRotation(false);
+ setDoRotation(false);
}
@Override
public void removeTileRendererNotify(TileRendererBase tr) {
tileRendererInUse = null;
- setDoRotation(doRotateBeforePrinting);
+ setDoRotation(doRotateBeforePrinting);
}
@Override
public void startTileRendering(TileRendererBase tr) {
@@ -68,10 +70,11 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
public void endTileRendering(TileRendererBase tr) {
System.err.println("Gears.endTileRendering: "+tr);
}
-
+
public void setDoRotation(boolean rotate) { doRotate = rotate; }
public void setVerbose(boolean v) { verbose = v; }
-
+ public void setFlipVerticalInGLOrientation(boolean v) { flipVerticalInGLOrientation=v; }
+
public void setGears(int g1, int g2, int g3) {
gear1 = g1;
gear2 = g2;
@@ -98,24 +101,24 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
GL2 gl = drawable.getGL().getGL2();
init(gl);
-
+
final Object upstreamWidget = drawable.getUpstreamWidget();
- if (upstreamWidget instanceof Window) {
+ if (upstreamWidget instanceof Window) {
final Window window = (Window) upstreamWidget;
window.addMouseListener(gearsMouse);
window.addKeyListener(gearsKeys);
} else if (GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) {
final java.awt.Component comp = (java.awt.Component) upstreamWidget;
new AWTMouseAdapter(gearsMouse).addTo(comp);
- new AWTKeyAdapter(gearsKeys).addTo(comp);
+ new AWTKeyAdapter(gearsKeys).addTo(comp);
}
}
-
+
public void init(GL2 gl) {
- float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
- float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
- float green[] = { 0.0f, 0.8f, 0.2f, 0.7f };
- float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
+ final float lightPos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
+ final float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
+ final float green[] = { 0.0f, 0.8f, 0.2f, 0.7f };
+ final float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
System.err.println(Thread.currentThread()+" Gears.init: tileRendererInUse "+tileRendererInUse);
if(verbose) {
@@ -124,13 +127,16 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
System.err.println("INIT GL IS: " + gl.getClass().getName());
System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
}
-
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0);
- gl.glEnable(GL2.GL_CULL_FACE);
+
+ gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPos, 0);
+ if( ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) ) {
+ // Only possible if we do not flip the projection matrix
+ gl.glEnable(GL2.GL_CULL_FACE);
+ }
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
gl.glEnable(GL2.GL_DEPTH_TEST);
-
+
/* make the gears */
if(0>=gear1) {
gear1 = gl.glGenLists(1);
@@ -142,7 +148,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
} else {
System.err.println("gear1 list reused: "+gear1);
}
-
+
if(0>=gear2) {
gear2 = gl.glGenLists(1);
gl.glNewList(gear2, GL2.GL_COMPILE);
@@ -153,7 +159,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
} else {
System.err.println("gear2 list reused: "+gear2);
}
-
+
if(0>=gear3) {
gear3 = gl.glGenLists(1);
gl.glNewList(gear3, GL2.GL_COMPILE);
@@ -164,14 +170,14 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
} else {
System.err.println("gear3 list reused: "+gear3);
}
-
+
gl.glEnable(GL2.GL_NORMALIZE);
}
-
+
@Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
final GL2 gl = glad.getGL().getGL2();
- if(-1 != swapInterval) {
+ if(-1 != swapInterval) {
gl.setSwapInterval(swapInterval);
}
reshape(gl, x, y, width, height, width, height);
@@ -179,7 +185,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
@Override
public void reshapeTile(TileRendererBase tr,
- int tileX, int tileY, int tileWidth, int tileHeight,
+ int tileX, int tileY, int tileWidth, int tileHeight,
int imageWidth, int imageHeight) {
final GL2 gl = tr.getAttachedDrawable().getGL().getGL2();
gl.setSwapInterval(0);
@@ -193,13 +199,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
if( msaa ) {
gl.glEnable(GL.GL_MULTISAMPLE);
}
-
- gl.glMatrixMode(GL2.GL_PROJECTION);
- gl.glLoadIdentity();
-
// compute projection parameters 'normal'
- float left, right, bottom, top;
+ float left, right, bottom, top;
if( imageHeight > imageWidth ) {
float a = (float)imageHeight / (float)imageWidth;
left = -1.0f;
@@ -215,24 +217,31 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
}
final float w = right - left;
final float h = top - bottom;
-
+
// compute projection parameters 'tiled'
final float l = left + tileX * w / imageWidth;
final float r = l + tileWidth * w / imageWidth;
+
final float b = bottom + tileY * h / imageHeight;
final float t = b + tileHeight * h / imageHeight;
final float _w = r - l;
final float _h = t - b;
if(verbose) {
- System.err.println(">> angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h);
+ System.err.println(">> Gears angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h+", v-flip "+flipVerticalInGLOrientation);
+ }
+
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glLoadIdentity();
+ if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
+ gl.glScalef(1f, -1f, 1f);
}
gl.glFrustum(l, r, b, t, 5.0f, 60.0f);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -40.0f);
-
+
if( msaa ) {
gl.glDisable(GL.GL_MULTISAMPLE);
}
@@ -243,7 +252,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
System.err.println(Thread.currentThread()+" Gears.dispose: tileRendererInUse "+tileRendererInUse);
try {
final Object upstreamWidget = drawable.getUpstreamWidget();
- if (upstreamWidget instanceof Window) {
+ if (upstreamWidget instanceof Window) {
final Window window = (Window) upstreamWidget;
window.removeMouseListener(gearsMouse);
window.removeKeyListener(gearsKeys);
@@ -261,7 +270,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
if( msaa ) {
gl.glEnable(GL.GL_MULTISAMPLE);
}
-
+
if( null == tileRendererInUse ) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
} else {
@@ -270,7 +279,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
// Special handling for the case where the GLJPanel is translucent
// and wants to be composited with other Java 2D content
- if (GLProfile.isAWTAvailable() &&
+ if (GLProfile.isAWTAvailable() &&
(drawable instanceof javax.media.opengl.awt.GLJPanel) &&
!((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() &&
((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
@@ -310,31 +319,31 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
-
+
// Place the first gear and call its display list
gl.glPushMatrix();
gl.glTranslatef(-3.0f, -2.0f, 0.0f);
gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
gl.glCallList(gear1);
gl.glPopMatrix();
-
+
// Place the second gear and call its display list
gl.glPushMatrix();
gl.glTranslatef(3.1f, -2.0f, 0.0f);
gl.glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
gl.glCallList(gear2);
gl.glPopMatrix();
-
+
// Place the third gear and call its display list
gl.glPushMatrix();
gl.glTranslatef(-3.1f, 4.2f, 0.0f);
gl.glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
gl.glCallList(gear3);
gl.glPopMatrix();
-
+
// Remember that every push needs a pop; this one is paired with
// rotating the entire gear assembly
- gl.glPopMatrix();
+ gl.glPopMatrix();
}
public static void gear(GL2 gl,
@@ -352,9 +361,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0f;
r2 = outer_radius + tooth_depth / 2.0f;
-
+
da = 2.0f * (float) Math.PI / teeth / 4.0f;
-
+
gl.glShadeModel(GL2.GL_FLAT);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
@@ -385,7 +394,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glVertex3f(r1 * (float)Math.cos(angle + 3.0f * da), r1 * (float)Math.sin(angle + 3.0f * da), width * 0.5f);
}
gl.glEnd();
-
+
/* draw back face */
gl.glBegin(GL2.GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++)
@@ -397,7 +406,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glVertex3f(r0 * (float)Math.cos(angle), r0 * (float)Math.sin(angle), -width * 0.5f);
}
gl.glEnd();
-
+
/* draw back sides of teeth */
gl.glBegin(GL2.GL_QUADS);
for (i = 0; i < teeth; i++)
@@ -409,7 +418,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glVertex3f(r1 * (float)Math.cos(angle), r1 * (float)Math.sin(angle), -width * 0.5f);
}
gl.glEnd();
-
+
/* draw outward faces of teeth */
gl.glBegin(GL2.GL_QUAD_STRIP);
for (i = 0; i < teeth; i++)
@@ -438,9 +447,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), width * 0.5f);
gl.glVertex3f(r1 * (float)Math.cos(0), r1 * (float)Math.sin(0), -width * 0.5f);
gl.glEnd();
-
+
gl.glShadeModel(GL2.GL_SMOOTH);
-
+
/* draw inside radius cylinder */
gl.glBegin(GL2.GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++)
@@ -453,7 +462,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
gl.glEnd();
}
- class GearsKeyAdapter extends KeyAdapter {
+ class GearsKeyAdapter extends KeyAdapter {
public void keyPressed(KeyEvent e) {
int kc = e.getKeyCode();
if(KeyEvent.VK_LEFT == kc) {
@@ -467,7 +476,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
}
}
}
-
+
class GearsMouseAdapter extends MouseAdapter {
public void mousePressed(MouseEvent e) {
prevMouseX = e.getX();
@@ -476,13 +485,13 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
// mouseRButtonDown = true;
}
}
-
+
public void mouseReleased(MouseEvent e) {
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
// mouseRButtonDown = false;
}
}
-
+
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
@@ -501,7 +510,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererList
}
float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
-
+
prevMouseX = x;
prevMouseY = y;