diff options
Diffstat (limited to 'src/demos/com/jogamp')
4 files changed, 71 insertions, 73 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneTextAnim01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneTextAnim01.java index 8658fdf4d..19fa5f0a6 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneTextAnim01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/GPUUISceneTextAnim01.java @@ -35,21 +35,15 @@ import java.util.Locale; import com.jogamp.common.util.IOUtil; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.font.FontScale; -import com.jogamp.graph.geom.SVertex; import com.jogamp.graph.ui.gl.Scene; import com.jogamp.graph.ui.gl.Shape; import com.jogamp.graph.ui.gl.shapes.Label; import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.Window; -import com.jogamp.newt.event.GestureHandler.GestureEvent; -import com.jogamp.newt.event.InputEvent; import com.jogamp.newt.event.MouseEvent; -import com.jogamp.newt.event.MouseEvent.PointerClass; -import com.jogamp.newt.event.PinchToZoomGesture; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2ES2; @@ -61,7 +55,6 @@ import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.demos.graph.FontSetDemos; import com.jogamp.opengl.demos.graph.MSAATool; import com.jogamp.opengl.math.FloatUtil; -import com.jogamp.opengl.math.VectorUtil; import com.jogamp.opengl.util.GLReadBufferUtil; public class GPUUISceneTextAnim01 implements GLEventListener { @@ -70,7 +63,7 @@ public class GPUUISceneTextAnim01 implements GLEventListener { private boolean trace = false; private final float noAADPIThreshold; - private final Scene sceneUICntrl; + private final Scene scene; /** -1 == AUTO, TBD @ init(..) */ private int renderModes; @@ -78,9 +71,6 @@ public class GPUUISceneTextAnim01 implements GLEventListener { private final Font font; private final Font fontFPS; - private final float sceneDist = 3000f; - private final float zNear = 0.1f, zFar = 7000f; - // private final float relTop = 80f/100f; private final float relMiddle = 22f/100f; // private final float relLeft = 11f/100f; @@ -135,23 +125,15 @@ public class GPUUISceneTextAnim01 implements GLEventListener { throw new RuntimeException(ioe); } - { - final RenderState rs = RenderState.createRenderState(SVertex.factory()); - final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); - rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED); - // renderer = RegionRenderer.create(rs, null, null); - - sceneUICntrl = new Scene(renderer, sceneDist, zNear, zFar); - // sceneUIController.setSampleCount(3); // easy on embedded devices w/ just 3 samples (default is 4)? - } + scene = new Scene(); screenshot = new GLReadBufferUtil(false, false); } private void setupUI(final GLAutoDrawable drawable) { final float pixelSizeFixed = fontSizeFixedPVP * drawable.getSurfaceHeight(); - jogampLabel = new Label(sceneUICntrl.getVertexFactory(), renderModes, font, pixelSizeFixed, jogamp); + jogampLabel = new Label(scene.getVertexFactory(), renderModes, font, pixelSizeFixed, jogamp); jogampLabel.addMouseListener(dragZoomRotateListener); - sceneUICntrl.addShape(jogampLabel); + scene.addShape(jogampLabel); jogampLabel.setEnabled(true); final float pixelSize10Pt = FontScale.toPixels(fontSizePt, dpiV); @@ -163,9 +145,9 @@ public class GPUUISceneTextAnim01 implements GLEventListener { * [FPS] Display 112.88889 dpi, fontSize 12.0 ppi -> pixelSize 15.679012 */ final float pixelSizeFPS = fontSizeFpsPVP * drawable.getSurfaceHeight(); - fpsLabel = new Label(sceneUICntrl.getVertexFactory(), renderModes, fontFPS, pixelSizeFPS, "Nothing there yet"); + fpsLabel = new Label(scene.getVertexFactory(), renderModes, fontFPS, pixelSizeFPS, "Nothing there yet"); fpsLabel.addMouseListener(dragZoomRotateListener); - sceneUICntrl.addShape(fpsLabel); + scene.addShape(fpsLabel); fpsLabel.setEnabled(true); fpsLabel.setColor(0.1f, 0.1f, 0.1f, 1.0f); fpsLabel.move(0f, pixelSizeFPS * (fontFPS.getMetrics().getLineGap() - fontFPS.getMetrics().getDescent()), 0f); @@ -196,7 +178,7 @@ public class GPUUISceneTextAnim01 implements GLEventListener { if(drawable instanceof GLWindow) { System.err.println("GPUUISceneGLListener0A: init (1)"); final GLWindow glw = (GLWindow) drawable; - sceneUICntrl.attachInputListenerTo(glw); + scene.attachInputListenerTo(glw); } else { System.err.println("GPUUISceneGLListener0A: init (0)"); } @@ -217,7 +199,7 @@ public class GPUUISceneTextAnim01 implements GLEventListener { gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_BLEND); - sceneUICntrl.init(drawable); + scene.init(drawable); final GLAnimatorControl a = drawable.getAnimator(); if( null != a ) { @@ -241,7 +223,7 @@ public class GPUUISceneTextAnim01 implements GLEventListener { jogampLabel.setPosition(dxMiddleAbs, dyTopLabelAbs, dz); fpsLabel.move(0f, 0f, 0f); - sceneUICntrl.reshape(drawable, x, y, width, height); + scene.reshape(drawable, x, y, width, height); lastWidth = width; lastHeight = height; @@ -252,7 +234,7 @@ public class GPUUISceneTextAnim01 implements GLEventListener { public void dispose(final GLAutoDrawable drawable) { System.err.println("GPUUISceneGLListener0A: dispose"); - sceneUICntrl.dispose(drawable); // disposes all registered UIShapes + scene.dispose(drawable); // disposes all registered UIShapes final GL2ES2 gl = drawable.getGL().getGL2ES2(); screenshot.dispose(gl); @@ -261,11 +243,11 @@ public class GPUUISceneTextAnim01 implements GLEventListener { private int shotCount = 0; public void printScreen(final GL gl) { - final RegionRenderer renderer = sceneUICntrl.getRenderer(); + final RegionRenderer renderer = scene.getRenderer(); final String modeS = Region.getRenderModeString(jogampLabel.getRenderModes()); final String filename = String.format((Locale)null, "GraphUIDemo-shot%03d-%03dx%03d-S_%s_%02d.png", shotCount++, renderer.getWidth(), renderer.getHeight(), - modeS, sceneUICntrl.getSampleCount()); + modeS, scene.getSampleCount()); gl.glFinish(); // just make sure rendering finished .. if(screenshot.readPixels(gl, false)) { screenshot.write(new File(filename)); @@ -278,7 +260,7 @@ public class GPUUISceneTextAnim01 implements GLEventListener { if( fpsLabel.isEnabled() ) { final String text; if( null == actionText ) { - text = sceneUICntrl.getStatusText(drawable, renderModes, fpsLabel.getQuality(), dpiV); + text = scene.getStatusText(drawable, renderModes, fpsLabel.getQuality(), dpiV); } else if( null != drawable.getAnimator() ) { text = Scene.getStatusText(drawable.getAnimator())+", "+actionText; } else { @@ -288,15 +270,15 @@ public class GPUUISceneTextAnim01 implements GLEventListener { System.err.println(text); } } - sceneUICntrl.display(drawable); + scene.display(drawable); } public void attachInputListenerTo(final GLWindow window) { - sceneUICntrl.attachInputListenerTo(window); + scene.attachInputListenerTo(window); } public void detachInputListenerFrom(final GLWindow window) { - sceneUICntrl.detachInputListenerFrom(window); + scene.detachInputListenerFrom(window); } /** diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java index 7ac982a48..bc2353bb1 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo01.java @@ -36,7 +36,6 @@ import com.jogamp.common.net.Uri; import com.jogamp.common.util.InterruptSource; import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.RegionRenderer; -import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; import com.jogamp.graph.font.FontSet; @@ -44,7 +43,6 @@ import com.jogamp.graph.geom.SVertex; import com.jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.ui.gl.Scene; import com.jogamp.graph.ui.gl.Shape; -import com.jogamp.graph.ui.gl.Shape.EventInfo; import com.jogamp.graph.ui.gl.shapes.Button; import com.jogamp.graph.ui.gl.shapes.GLButton; import com.jogamp.graph.ui.gl.shapes.MediaButton; @@ -62,10 +60,8 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLPipelineFactory; import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.GLRunnable; import com.jogamp.opengl.demos.es2.GearsES2; import com.jogamp.opengl.demos.graph.MSAATool; -import com.jogamp.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.GLReadBufferUtil; import com.jogamp.opengl.util.PMVMatrix; @@ -156,9 +152,6 @@ public class UISceneDemo01 implements GLEventListener { private final float[] position = new float[] {0,0,0}; - private final float sceneDist = -1/5f; - private final float zNear = 0.1f, zFar = 7000f; - boolean ignoreInput = false; protected final AffineTransform tempT1 = new AffineTransform(); @@ -253,11 +246,11 @@ public class UISceneDemo01 implements GLEventListener { s.setTransform(pmv); final float[] objPos = new float[3]; - s.winToObjCoord(renderer, glWinX, glWinY, objPos); + s.winToObjCoord(pmv, viewport, glWinX, glWinY, objPos); System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos[0]+"/"+objPos[1]+"/"+objPos[1]); final int[] surfaceSize = new int[2]; - s.getSurfaceSize(renderer, surfaceSize); + s.getSurfaceSize(pmv, viewport, surfaceSize); System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); @@ -314,6 +307,22 @@ public class UISceneDemo01 implements GLEventListener { @Override public void display(final GLAutoDrawable drawable) { scene.display(drawable); + if( once ) { + once = false; + final RegionRenderer renderer = scene.getRenderer(); + final PMVMatrix pmv = renderer.getMatrix(); + pmv.glPushMatrix(); + shape.setTransform(pmv); + + final int[] winPosSize = { 0, 0 }; + System.err.println("draw.0: "+shape); + boolean ok = shape.getSurfaceSize(pmv, renderer.getViewport(), winPosSize); + System.err.println("draw.1: ok "+ok+", surfaceSize "+winPosSize[0]+" x "+winPosSize[1]); + ok = shape.objToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), winPosSize); + System.err.println("draw.2: ok "+ok+", winCoord "+winPosSize[0]+" x "+winPosSize[1]); + + pmv.glPopMatrix(); + } } static boolean once = true; diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java index 81d657385..61f5a37ac 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UIShapeDemo01.java @@ -104,8 +104,10 @@ public class UIShapeDemo01 implements GLEventListener { final GLProfile glp = GLProfile.getGL2ES2(); final GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); - caps.setSampleBuffers(true); - caps.setNumSamples(4); + if( false ) { + caps.setSampleBuffers(true); + caps.setNumSamples(4); + } System.out.println("Requested: " + caps); final GLWindow window = GLWindow.create(caps); @@ -180,7 +182,9 @@ public class UIShapeDemo01 implements GLEventListener { this.trace = trace; this.screenshot = new GLReadBufferUtil(false, false); - button = new Button(SVertex.factory(), renderModes, font, "Click me!", 1/8f, 1/16f); + final float sz1_w = 1/8f; + final float sz2 = 1/20f; + button = new Button(SVertex.factory(), renderModes, font, "Click me!", sz1_w, sz1_w/2f); button.setLabelColor(0.0f,0.0f,0.0f); /** Button defaults ! button.setLabelColor(1.0f,1.0f,1.0f); @@ -189,7 +193,7 @@ public class UIShapeDemo01 implements GLEventListener { button.setSpacing(2.0f); */ System.err.println(button); - crossHair = new CrossHair(SVertex.factory(), renderModes, 1/20f, 1/20f, 1/1000f); + crossHair = new CrossHair(SVertex.factory(), renderModes, sz2, sz2, 1/1000f); crossHair.setColor(0f,0f,1f,1f); crossHair.setEnabled(true); } @@ -218,25 +222,37 @@ public class UIShapeDemo01 implements GLEventListener { @Override public void reshape(final GLAutoDrawable drawable, final int xstart, final int ystart, final int width, final int height) { - final GL2ES2 gl = drawable.getGL().getGL2ES2(); + // final GL2ES2 gl = drawable.getGL().getGL2ES2(); + // gl.glViewport(xstart, ystart, width, height); rRenderer.reshapePerspective(45.0f, width, height, zNear, zFar); // rRenderer.reshapeOrtho(width, height, zNear, zFar); - lastWidth = width; - lastHeight = height; + final PMVMatrix pmv = rRenderer.getMatrix(); + pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmv.glLoadIdentity(); + pmv.glTranslatef(xTran, yTran, zTran); + if( drawable instanceof Window ) { ((Window)drawable).setTitle(UIShapeDemo01.class.getSimpleName()+": "+drawable.getSurfaceWidth()+" x "+drawable.getSurfaceHeight()); } } - float lastWidth = 0f, lastHeight = 0f; final int[] sampleCount = { 4 }; - private void drawShape(final GL2ES2 gl, final PMVMatrix pmv, final RegionRenderer renderer, final Shape shape) { + private void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final Shape shape) { + final PMVMatrix pmv = renderer.getMatrix(); pmv.glPushMatrix(); shape.setTransform(pmv); shape.drawShape(gl, renderer, sampleCount); + if( once ) { + final int[] winPosSize = { 0, 0 }; + System.err.println("draw.0: "+shape); + boolean ok = shape.getSurfaceSize(pmv, renderer.getViewport(), winPosSize); + System.err.println("draw.1: ok "+ok+", surfaceSize "+winPosSize[0]+" x "+winPosSize[1]); + ok = shape.objToWinCoord(pmv, renderer.getViewport(), shape.getPosition(), winPosSize); + System.err.println("draw.2: ok "+ok+", winCoord "+winPosSize[0]+" x "+winPosSize[1]); + } pmv.glPopMatrix(); } @@ -249,12 +265,9 @@ public class UIShapeDemo01 implements GLEventListener { final RegionRenderer renderer = getRegionRenderer(); final PMVMatrix pmv = renderer.getMatrix(); - pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - pmv.glLoadIdentity(); - pmv.glTranslatef(xTran, yTran, zTran); renderer.enable(gl, true); - drawShape(gl, pmv, renderer, button); - drawShape(gl, pmv, renderer, crossHair); + drawShape(gl, renderer, button); + drawShape(gl, renderer, crossHair); { final String text = "Hello Origin."; final float full_width_o; @@ -392,11 +405,11 @@ public class UIShapeDemo01 implements GLEventListener { final float[] objPos = new float[3]; System.err.println("\n\nButton: "+button); - button.winToObjCoord(renderer, glWinX, glWinY, objPos); + button.winToObjCoord(pmv, viewport, glWinX, glWinY, objPos); System.err.println("Button: Click: Win "+glWinX+"/"+glWinY+" -> Obj "+objPos[0]+"/"+objPos[1]+"/"+objPos[1]); final int[] surfaceSize = new int[2]; - button.getSurfaceSize(renderer, surfaceSize); + button.getSurfaceSize(pmv, viewport, surfaceSize); System.err.println("Button: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); @@ -408,16 +421,16 @@ public class UIShapeDemo01 implements GLEventListener { final float[] objPosC = crossHair.getBounds().getCenter(); final int[] objWinPos = new int[2]; System.err.println("\n\nCrossHair: "+crossHair); - if( crossHair.objToWinCoord(renderer, objPosC, objWinPos) ) { + if( crossHair.objToWinCoord(pmv, viewport, objPosC, objWinPos) ) { System.err.println("CrossHair: Obj: Obj "+objPosC[0]+"/"+objPosC[1]+"/"+objPosC[1]+" -> Win "+objWinPos[0]+"/"+objWinPos[1]); } final float[] objPos2 = new float[3]; - crossHair.winToObjCoord(renderer, objWinPos[0], objWinPos[1], objPos2); + crossHair.winToObjCoord(pmv, viewport, objWinPos[0], objWinPos[1], objPos2); System.err.println("CrossHair: Obj: Win "+objWinPos[0]+"/"+objWinPos[1]+" -> Obj "+objPos2[0]+"/"+objPos2[1]+"/"+objPos2[1]); final float[] winObjPos = new float[3]; - if( crossHair.winToObjCoord(renderer, glWinX, glWinY, winObjPos) ) { + if( crossHair.winToObjCoord(pmv, viewport, glWinX, glWinY, winObjPos) ) { // final float[] translate = crossHair.getTranslate(); // final float[] objPosT = new float[] { objPosC[0]+translate[0], objPosC[1]+translate[1], objPosC[2]+translate[2] }; final float dx = winObjPos[0] - objPosC[0]; @@ -432,7 +445,7 @@ public class UIShapeDemo01 implements GLEventListener { } final int[] surfaceSize = new int[2]; - crossHair.getSurfaceSize(renderer, surfaceSize); + crossHair.getSurfaceSize(pmv, viewport, surfaceSize); System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); @@ -448,20 +461,14 @@ public class UIShapeDemo01 implements GLEventListener { @Override public void mouseMoved(final MouseEvent e) { - // TODO Auto-generated method stub - } @Override public void mouseDragged(final MouseEvent e) { - // TODO Auto-generated method stub - } @Override public void mouseWheelMoved(final MouseEvent e) { - // TODO Auto-generated method stub - } } diff --git a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java index 56962e110..41235077e 100644 --- a/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java +++ b/src/demos/com/jogamp/opengl/demos/graph/ui/UITypeDemo01.java @@ -475,16 +475,16 @@ public class UITypeDemo01 implements GLEventListener { final float[] objPosC = crossHair.getBounds().getCenter(); final int[] objWinPos = new int[2]; System.err.println("\n\nCrossHair: "+crossHair); - if( crossHair.objToWinCoord(renderer, objPosC, objWinPos) ) { + if( crossHair.objToWinCoord(pmv, viewport, objPosC, objWinPos) ) { System.err.println("CrossHair: Obj: Obj "+objPosC[0]+"/"+objPosC[1]+"/"+objPosC[1]+" -> Win "+objWinPos[0]+"/"+objWinPos[1]); } final float[] objPos2 = new float[3]; - crossHair.winToObjCoord(renderer, objWinPos[0], objWinPos[1], objPos2); + crossHair.winToObjCoord(pmv, viewport, objWinPos[0], objWinPos[1], objPos2); System.err.println("CrossHair: Obj: Win "+objWinPos[0]+"/"+objWinPos[1]+" -> Obj "+objPos2[0]+"/"+objPos2[1]+"/"+objPos2[1]); final float[] winObjPos = new float[3]; - if( crossHair.winToObjCoord(renderer, glWinX, glWinY, winObjPos) ) { + if( crossHair.winToObjCoord(pmv, viewport, glWinX, glWinY, winObjPos) ) { // final float[] translate = crossHair.getTranslate(); // final float[] objPosT = new float[] { objPosC[0]+translate[0], objPosC[1]+translate[1], objPosC[2]+translate[2] }; final float dx = winObjPos[0] - objPosC[0]; @@ -499,7 +499,7 @@ public class UITypeDemo01 implements GLEventListener { } final int[] surfaceSize = new int[2]; - crossHair.getSurfaceSize(renderer, surfaceSize); + crossHair.getSurfaceSize(pmv, viewport, surfaceSize); System.err.println("CrossHair: Size: Pixel "+surfaceSize[0]+" x "+surfaceSize[1]); pmv.glPopMatrix(); |