aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-09-10 23:37:14 +0200
committerSven Gothel <[email protected]>2013-09-10 23:37:14 +0200
commit569c538b439275222ed40c249f4ecd7516c2945b (patch)
treeadd0c3b7afafd20c320cf28cc8f09ee4706ddc29 /src/test
parentd2be196ba129ff5b690189a95ba21137523c3352 (diff)
TestTiledPrintingGearsSwingAWT: Add a second demo GLEventListener showing it's working/scaling well; Adding TileRendererBase.TileRendererNotify to RedAquareES2 having a 3rd demo case.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java65
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java11
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java43
4 files changed, 104 insertions, 25 deletions
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 d8e0347d8..3da53c4c0 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
@@ -269,7 +269,8 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererN
imageWidth = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_WIDTH);
imageHeight = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_HEIGHT);
}
- /* compute projection parameters */
+
+ // compute projection parameters 'normal'
float left, right, bottom, top;
if( imageHeight > imageWidth ) {
float a = (float)imageHeight / (float)imageWidth;
@@ -286,6 +287,8 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererN
}
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;
@@ -293,7 +296,10 @@ public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererN
final float _w = r - l;
final float _h = t - b;
- 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);
+ 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);
+ }
+
pmvMatrix.glFrustumf(l, r, b, t, 5.0f, 200.0f);
pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
index 1ba4d126f..5315fe406 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
@@ -30,6 +30,7 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2;
import com.jogamp.opengl.JoglVersion;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.TileRendererBase;
import com.jogamp.opengl.util.glsl.ShaderCode;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.glsl.ShaderState;
@@ -39,7 +40,7 @@ import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLUniformData;
-public class RedSquareES2 implements GLEventListener {
+public class RedSquareES2 implements GLEventListener, TileRendererBase.TileRendererNotify {
private ShaderState st;
private PMVMatrix pmvMatrix;
private GLUniformData pmvMatrixUniform;
@@ -50,6 +51,8 @@ public class RedSquareES2 implements GLEventListener {
private float aspect = 1.0f;
private boolean doRotate = true;
private boolean clearBuffers = true;
+ private TileRendererBase tileRendererInUse = null;
+ private boolean doRotateBeforePrinting;
public RedSquareES2(int swapInterval) {
this.swapInterval = swapInterval;
@@ -59,6 +62,15 @@ public class RedSquareES2 implements GLEventListener {
this.swapInterval = 1;
}
+ public void addTileRendererNotify(TileRendererBase tr) {
+ tileRendererInUse = tr;
+ doRotateBeforePrinting = doRotate;
+ setDoRotation(false);
+ }
+ public void removeTileRendererNotify(TileRendererBase tr) {
+ tileRendererInUse = null;
+ setDoRotation(doRotateBeforePrinting);
+ }
public void setAspect(float aspect) { this.aspect = aspect; }
public void setDoRotation(boolean rotate) { this.doRotate = rotate; }
public void setClearBuffers(boolean v) { clearBuffers = v; }
@@ -131,7 +143,11 @@ public class RedSquareES2 implements GLEventListener {
final GL2ES2 gl = glad.getGL().getGL2ES2();
if( clearBuffers ) {
- gl.glClearColor(0, 0, 0, 0);
+ if( null != tileRendererInUse ) {
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+ } else {
+ gl.glClearColor(0, 0, 0, 0);
+ }
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
if( !gl.hasGLSL() ) {
@@ -166,15 +182,50 @@ public class RedSquareES2 implements GLEventListener {
return;
}
- if(-1 != swapInterval) {
- gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
- }
-
st.useProgram(gl, true);
// Set location in front of camera
pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
pmvMatrix.glLoadIdentity();
- pmvMatrix.gluPerspective(45.0F, ( (float) width / (float) height ) / aspect, 1.0F, 100.0F);
+
+ final int tileWidth = width;
+ final int tileHeight = height;
+ final int tileX, tileY, imageWidth, imageHeight;
+ if( null == tileRendererInUse ) {
+ if(-1 != swapInterval) {
+ gl.setSwapInterval(swapInterval);
+ }
+ tileX = 0;
+ tileY = 0;
+ imageWidth = width;
+ imageHeight = height;
+ } else {
+ gl.setSwapInterval(0);
+ tileX = tileRendererInUse.getParam(TileRendererBase.TR_CURRENT_TILE_X_POS);
+ tileY = tileRendererInUse.getParam(TileRendererBase.TR_CURRENT_TILE_Y_POS);
+ imageWidth = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_WIDTH);
+ imageHeight = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_HEIGHT);
+ }
+ // compute projection parameters 'normal' perspective
+ final float fovy=45f;
+ final float aspect2 = ( (float) width / (float) height ) / 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;
+ final float left=aspect2*bottom;
+ 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;
+
+ pmvMatrix.glFrustumf(l, r, b, t, zNear, zFar);
//pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
st.uniform(gl, pmvMatrixUniform);
st.useProgram(gl, false);
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 80e145c67..1d992de68 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
@@ -36,6 +36,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti
private KeyListener gearsKeys = new GearsKeyAdapter();
private TileRendererBase tileRendererInUse = null;
private boolean doRotateBeforePrinting;
+ private boolean verbose = true;
// private boolean mouseRButtonDown = false;
private int prevMouseX, prevMouseY;
@@ -59,6 +60,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti
}
public void setDoRotation(boolean rotate) { doRotate = rotate; }
+ public void setVerbose(boolean v) { verbose = v; }
public void setGears(int g1, int g2, int g3) {
gear1 = g1;
@@ -185,7 +187,8 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti
imageWidth = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_WIDTH);
imageHeight = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_HEIGHT);
}
- /* compute projection parameters */
+
+ // compute projection parameters 'normal'
float left, right, bottom, top;
if( imageHeight > imageWidth ) {
float a = (float)imageHeight / (float)imageWidth;
@@ -202,6 +205,8 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti
}
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;
@@ -209,7 +214,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti
final float _w = r - l;
final float _h = t - b;
- 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);
+ 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);
+ }
gl.glFrustum(l, r, b, t, 5.0f, 60.0f);
gl.glMatrixMode(GL2.GL_MODELVIEW);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
index d63f73924..da577ea1d 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
@@ -60,6 +60,7 @@ import com.jogamp.newt.event.TraceKeyAdapter;
import com.jogamp.newt.event.TraceWindowAdapter;
import com.jogamp.newt.event.awt.AWTKeyAdapter;
import com.jogamp.newt.event.awt.AWTWindowAdapter;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.QuitAdapter;
@@ -93,15 +94,24 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
}
protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException {
- final GLJPanel glJPanel = new GLJPanel(caps);
- Assert.assertNotNull(glJPanel);
- Dimension glc_sz = new Dimension(width, height);
- glJPanel.setMinimumSize(glc_sz);
- glJPanel.setPreferredSize(glc_sz);
- glJPanel.setSize(glc_sz);
+ final Dimension glc_sz = new Dimension(width/2, height);
+ final GLJPanel glJPanel1 = new GLJPanel(caps);
+ Assert.assertNotNull(glJPanel1);
+ glJPanel1.setMinimumSize(glc_sz);
+ glJPanel1.setPreferredSize(glc_sz);
+ glJPanel1.setSize(glc_sz);
+ glJPanel1.addGLEventListener(new Gears());
- final Gears gears = new Gears();
- glJPanel.addGLEventListener(gears);
+ final GLJPanel glJPanel2 = new GLJPanel(caps);
+ Assert.assertNotNull(glJPanel2);
+ glJPanel2.setMinimumSize(glc_sz);
+ glJPanel2.setPreferredSize(glc_sz);
+ glJPanel2.setSize(glc_sz);
+ glJPanel2.addGLEventListener(new RedSquareES2());
+
+ final JPanel demoPanel = new JPanel();
+ demoPanel.add(glJPanel1);
+ demoPanel.add(glJPanel2);
final JFrame frame = new JFrame("Swing Print");
Assert.assertNotNull(frame);
@@ -136,10 +146,13 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
final JPanel westPanel = new JPanel();
westPanel.add(new Label("West"));
- Animator animator = new Animator(glJPanel);
+ Animator animator = new Animator();
+ animator.add(glJPanel1);
+ animator.add(glJPanel2);
QuitAdapter quitAdapter = new QuitAdapter();
- new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glJPanel);
+ new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glJPanel1);
+ new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glJPanel2);
new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame);
SwingUtilities.invokeAndWait(new Runnable() {
@@ -147,7 +160,7 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
final Container fcont = frame.getContentPane();
fcont.setLayout(new BorderLayout());
fcont.add(printPanel, BorderLayout.NORTH);
- fcont.add(glJPanel, BorderLayout.CENTER);
+ fcont.add(demoPanel, BorderLayout.CENTER);
fcont.add(southPanel, BorderLayout.SOUTH);
fcont.add(eastPanel, BorderLayout.EAST);
fcont.add(westPanel, BorderLayout.WEST);
@@ -157,7 +170,8 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
} } ) ;
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
- Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel2, true));
animator.setUpdateFPSFrames(60, System.err);
animator.start();
@@ -184,7 +198,8 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
// try { Thread.sleep(4000); } catch (InterruptedException e) { } // time to finish print jobs .. FIXME ??
Assert.assertNotNull(frame);
- Assert.assertNotNull(glJPanel);
+ Assert.assertNotNull(glJPanel1);
+ Assert.assertNotNull(glJPanel2);
Assert.assertNotNull(animator);
animator.stop();
@@ -197,7 +212,7 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
final Frame _frame = frame;
- _frame.remove(glJPanel);
+ _frame.remove(demoPanel);
_frame.dispose();
}});
}