diff options
Diffstat (limited to 'src/test/com/jogamp/opengl')
5 files changed, 67 insertions, 22 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java index ba47d7e4f..9e6c131ed 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/GLEventListenerButton.java @@ -84,6 +84,9 @@ public class GLEventListenerButton extends TextureSeqButton { @Override public void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final int[] sampleCount) { + final int[/*2*/] surfaceSize = new int[2]; + final boolean got_sz = getSurfaceSize(renderer, surfaceSize); + if( null == fboGLAD ) { final ImageSequence imgSeq = (ImageSequence)texSeq; @@ -119,6 +122,22 @@ public class GLEventListenerButton extends TextureSeqButton { fboWidth = 0; fboHeight = 0; markStateDirty(); + } else if( got_sz && ( fboGLAD.getSurfaceWidth() != surfaceSize[0] || fboGLAD.getSurfaceHeight() != surfaceSize[1] ) ) { + // System.err.println("XXX FBO setSurfaceSize "+fboGLAD.getSurfaceWidth()+" x "+fboGLAD.getSurfaceHeight()+" -> "+surfaceSize[0]+" x "+surfaceSize[1]); + final ImageSequence imgSeq = (ImageSequence)texSeq; + + fboGLAD.setSurfaceSize(surfaceSize[0], surfaceSize[1]); + fboGLAD.display(); // re-init! + + imgSeq.destroy(gl); + final FBObject.TextureAttachment texA01 = fboGLAD.getColorbuffer(GL.GL_FRONT).getTextureAttachment(); + final Texture tex = new Texture(texA01.getName(), imgSeq.getTextureTarget(), + fboGLAD.getSurfaceWidth(), fboGLAD.getSurfaceHeight(), fboGLAD.getSurfaceWidth(), fboGLAD.getSurfaceHeight(), + false /* mustFlipVertically */); + imgSeq.addFrame(gl, tex); + fboWidth = 0; + fboHeight = 0; + markStateDirty(); } else if( animateGLEL ) { fboGLAD.display(); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java index 9de206cac..9757c3df9 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/SceneUIController.java @@ -249,7 +249,16 @@ public class SceneUIController implements GLEventListener{ cDrawable.invoke(false, new GLRunnable() { @Override public boolean run(final GLAutoDrawable drawable) { - if( activeShape.winToObjCoord(renderer, glWinX, glWinY, objPos) ) { + final boolean ok; + { + final PMVMatrix pmv = renderer.getMatrix(); + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glPushMatrix(); + activeShape.setTransform(pmv); + ok = activeShape.winToObjCoord(renderer, glWinX, glWinY, objPos); + pmv.glPopMatrix(); + } + if( ok ) { runnable.run(); } return true; diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java index f8c04d4bf..3ee48504d 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShape.java @@ -298,6 +298,10 @@ public abstract class UIShape { } } + /** + * Setup the pre-selected {@link GLMatrixFunc#GL_MODELVIEW} {@link PMVMatrix} for this object. + * @param pmv the matrix + */ public void setTransform(final PMVMatrix pmv) { final float[] uiTranslate = getTranslate(); pmv.glTranslatef(uiTranslate[0], uiTranslate[1], uiTranslate[2]); @@ -326,16 +330,15 @@ public abstract class UIShape { /** * Retrieve window surface size of this shape - * @param renderer source of viewport and PMVMatrix + * <p> + * The {@link RegionRenderer#getMatrix()} has to be setup properly for this object, + * i.e. reshape for {@link GLMatrixFunc#GL_PROJECTION} and {@link #setTransform(PMVMatrix)} for {@link GLMatrixFunc#GL_MODELVIEW}. + * </p> + * @param renderer source of viewport and {@link PMVMatrix} * @param surfaceSize target surface size * @return true for successful gluProject(..) operation, otherwise false */ public boolean getSurfaceSize(final RegionRenderer renderer, final int[/*2*/] surfaceSize) { - final PMVMatrix pmv = renderer.getMatrix(); - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - - pmv.glPushMatrix(); - setTransform(pmv); boolean res = false; final int[/*4*/] viewport = renderer.getViewport(new int[4]); // System.err.println("UIShape::getSurfaceSize.VP "+viewport[0]+"/"+viewport[1]+" "+viewport[2]+"x"+viewport[3]); @@ -343,6 +346,7 @@ public abstract class UIShape { final float[] winCoordLow = new float[3]; final float[] high = getBounds().getHigh(); final float[] low = getBounds().getLow(); + final PMVMatrix pmv = renderer.getMatrix(); if( pmv.gluProject(high[0], high[1], high[2], viewport, 0, winCoordHigh, 0) ) { // System.err.printf("UIShape::surfaceSize.H: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", getName(), high[0], high[1], high[2], winCoordHigh[0], winCoordHigh[1], winCoordHigh[2]); @@ -354,27 +358,26 @@ public abstract class UIShape { res = true; } } - pmv.glPopMatrix(); return res; } /** * Map given object coordinate relative to this shape to window coordinates - * @param renderer source of viewport and PMVMatrix + * <p> + * The {@link RegionRenderer#getMatrix()} has to be setup properly for this object, + * i.e. reshape for {@link GLMatrixFunc#GL_PROJECTION} and {@link #setTransform(PMVMatrix)} for {@link GLMatrixFunc#GL_MODELVIEW}. + * </p> + * @param renderer source of viewport and {@link PMVMatrix} * @param objPos object position relative to this shape's center * @param glWinPos target window position of objPos relative to this shape * @return true for successful gluProject(..) operation, otherwise false */ public boolean objToWinCoord(final RegionRenderer renderer, final float[/*3*/] objPos, final int[/*2*/] glWinPos) { - final PMVMatrix pmv = renderer.getMatrix(); - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - - pmv.glPushMatrix(); - setTransform(pmv); boolean res = false; final int[/*4*/] viewport = renderer.getViewport(new int[4]); // System.err.println("UIShape::objToWinCoordgetSurfaceSize.VP "+viewport[0]+"/"+viewport[1]+" "+viewport[2]+"x"+viewport[3]); final float[] winCoord = new float[3]; + final PMVMatrix pmv = renderer.getMatrix(); if( pmv.gluProject(objPos[0], objPos[1], objPos[2], viewport, 0, winCoord, 0) ) { // System.err.printf("UIShape::objToWinCoord.0: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", getName(), objPos[0], objPos[1], objPos[2], winCoord[0], winCoord[1], winCoord[2]); @@ -383,28 +386,28 @@ public abstract class UIShape { // System.err.printf("UIShape::objToWinCoord.X: shape %d: %f / %f -> %d / %d%n", getName(), winCoord[0], winCoord[1], glWinPos[0], glWinPos[1]); res = true; } - pmv.glPopMatrix(); return res; } /** * Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate. - * @param renderer source of viewport and PMVMatrix + * <p> + * The {@link RegionRenderer#getMatrix()} has to be setup properly for this object, + * i.e. reshape for {@link GLMatrixFunc#GL_PROJECTION} and {@link #setTransform(PMVMatrix)} for {@link GLMatrixFunc#GL_MODELVIEW}. + * </p> + * @param renderer source of viewport and {@link PMVMatrix} * @param glWinX in GL window coordinates, origin bottom-left * @param glWinY in GL window coordinates, origin bottom-left * @param objPos target object position of glWinX/glWinY relative to this shape * @return @return true for successful gluProject(..) and gluUnProject(..) operations, otherwise false */ public boolean winToObjCoord(final RegionRenderer renderer, final int glWinX, final int glWinY, final float[/*3*/] objPos) { - final PMVMatrix pmv = renderer.getMatrix(); - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - - pmv.glPushMatrix(); - setTransform(pmv); boolean res = false; final float[] ctr = getBounds().getCenter(); final int[] viewport = renderer.getViewport(new int[4]); final float[] tmp = new float[3]; + final PMVMatrix pmv = renderer.getMatrix(); + if( pmv.gluProject(ctr[0], ctr[1], ctr[2], viewport, 0, tmp, 0) ) { // System.err.printf("UIShape::winToObjCoord.0: shape %d: obj [%f, %f, %f] -> win [%f, %f, %f]%n", getName(), ctr[0], ctr[1], ctr[2], tmp[0], tmp[1], tmp[2]); if( pmv.gluUnProject(glWinX, glWinY, tmp[2], viewport, 0, objPos, 0) ) { @@ -412,7 +415,6 @@ public abstract class UIShape { res = true; } } - pmv.glPopMatrix(); return res; } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShapeDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShapeDemo01.java index 4a61a2be0..66fca799e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShapeDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UIShapeDemo01.java @@ -385,6 +385,9 @@ public class UIShapeDemo01 implements GLEventListener { final int glWinY = viewport[3] - e.getY() - 1; { + pmv.glPushMatrix(); + button.setTransform(pmv); + final float[] objPos = new float[3]; System.err.println("\n\nButton: "+button); button.winToObjCoord(renderer, glWinX, glWinY, objPos); @@ -393,8 +396,13 @@ public class UIShapeDemo01 implements GLEventListener { final int[] surfaceSize = new int[2]; button.getSurfaceSize(renderer, surfaceSize); System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + + pmv.glPopMatrix(); } { + pmv.glPushMatrix(); + crossHair.setTransform(pmv); + final float[] objPosC = crossHair.getBounds().getCenter(); final int[] objWinPos = new int[2]; System.err.println("\n\nCrossHair: "+crossHair); @@ -424,6 +432,8 @@ public class UIShapeDemo01 implements GLEventListener { final int[] surfaceSize = new int[2]; crossHair.getSurfaceSize(renderer, surfaceSize); System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + + pmv.glPopMatrix(); } return true; } } ); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITypeDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITypeDemo01.java index b3a56d9b7..53f280672 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITypeDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UITypeDemo01.java @@ -439,6 +439,9 @@ public class UITypeDemo01 implements GLEventListener { final int glWinY = viewport[3] - e.getY() - 1; { + pmv.glPushMatrix(); + crossHair.setTransform(pmv); + final float[] objPosC = crossHair.getBounds().getCenter(); final int[] objWinPos = new int[2]; System.err.println("\n\nCrossHair: "+crossHair); @@ -468,6 +471,8 @@ public class UITypeDemo01 implements GLEventListener { final int[] surfaceSize = new int[2]; crossHair.getSurfaceSize(renderer, surfaceSize); System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); + + pmv.glPopMatrix(); } return true; } } ); |