From d341b3160c4af3bc1efb91c995abb44368f628a5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 15 Sep 2011 15:06:38 +0200 Subject: Graph Demos: Make GLEvenListener 'standalone'; UIScene to common package; Cleanup --- .../graph/demos/GPURendererListenerBase01.java | 3 +- .../junit/graph/demos/GPUTextGLListener0A.java | 20 ++ .../test/junit/graph/demos/GPUTextNewtDemo01.java | 1 - .../test/junit/graph/demos/GPUTextNewtDemo02.java | 1 - .../graph/demos/GPUTextRendererListenerBase01.java | 7 +- .../junit/graph/demos/GPUUISceneGLListener0A.java | 371 ++++++++++++++++++++ .../junit/graph/demos/GPUUISceneNewtDemo01.java | 49 +++ .../graph/demos/mobile/GPUGraphGLListenerMT.java | 377 --------------------- .../demos/mobile/GPUTextNewtDemoMobile01.java | 49 --- .../junit/graph/demos/ui/SceneUIController.java | 16 +- 10 files changed, 454 insertions(+), 440 deletions(-) create mode 100644 src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java create mode 100644 src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java delete mode 100644 src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java index 7a10c4950..dac965df3 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURendererListenerBase01.java @@ -180,11 +180,10 @@ public abstract class GPURendererListenerBase01 implements GLEventListener { } } - public void detachFrom(GLWindow window) { + public void detachInputListenerFrom(GLWindow window) { if ( null == keyAction ) { return; } - window.removeGLEventListener(this); window.removeKeyListener(keyAction); } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java index 6d97505c4..da34b1d78 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextGLListener0A.java @@ -33,14 +33,26 @@ import javax.media.opengl.GLAutoDrawable; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.graph.curve.opengl.TextRenderer; +import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.glsl.ShaderState; public class GPUTextGLListener0A extends GPUTextRendererListenerBase01 { + + public GPUTextGLListener0A() { + this( RenderState.createRenderState(new ShaderState(), SVertex.factory()), 0, 0, false, false ) ; + } + public GPUTextGLListener0A(RenderState rs, int numpass, int fbosize, boolean debug, boolean trace) { super(rs, numpass, debug, trace); setMatrix(-400, -30, 0f, -500, fbosize); } public void init(GLAutoDrawable drawable) { + if(drawable instanceof GLWindow) { + final GLWindow glw = (GLWindow) drawable; + attachInputListenerTo(glw); + } super.init(drawable); GL2ES2 gl = drawable.getGL().getGL2ES2(); @@ -54,4 +66,12 @@ public class GPUTextGLListener0A extends GPUTextRendererListenerBase01 { textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); MSAATool.dump(drawable); } + + public void dispose(GLAutoDrawable drawable) { + if(drawable instanceof GLWindow) { + final GLWindow glw = (GLWindow) drawable; + detachInputListenerFrom(glw); + } + super.dispose(drawable); + } } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java index b9a045498..bcd60d441 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java @@ -64,7 +64,6 @@ public class GPUTextNewtDemo01 { final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, 0, 0, DEBUG, TRACE); - textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index d7dff5170..5981e7971 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -73,7 +73,6 @@ public class GPUTextNewtDemo02 { RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); GPUTextGLListener0A textGLListener = new GPUTextGLListener0A(rs, Region.VBAA_RENDERING_BIT, window.getWidth()*3, DEBUG, TRACE); // ((TextRenderer)textGLListener.getRenderer()).setCacheLimit(32); - textGLListener.attachInputListenerTo(window); window.addGLEventListener(textGLListener); window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java index 0fced4715..ad662e000 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java @@ -229,13 +229,12 @@ public abstract class GPUTextRendererListenerBase01 extends GPURendererListenerB keyAction = new KeyAction(); window.addKeyListener(keyAction); super.attachInputListenerTo(window); - } - + } } @Override - public void detachFrom(GLWindow window) { - super.detachFrom(window); + public void detachInputListenerFrom(GLWindow window) { + super.detachInputListenerFrom(window); if ( null == keyAction ) { return; } diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java new file mode 100644 index 000000000..476bbc04f --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java @@ -0,0 +1,371 @@ +package com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLPipelineFactory; +import javax.media.opengl.GLRunnable; + +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.geom.opengl.SVertex; +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.graph.demos.ui.Label; +import com.jogamp.opengl.test.junit.graph.demos.ui.RIButton; +import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController; +import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion; +import com.jogamp.opengl.util.glsl.ShaderState; + +public class GPUUISceneGLListener0A implements GLEventListener { + + private boolean debug = false; + private boolean trace = false; + + private RegionRenderer regionRenderer; + private RenderState rs; + + int fontSet = FontFactory.UBUNTU; + Font font; + final int fontSizeFixed = 6; + + private float xTran = 0; + private float yTran = 0; + private float ang = 0f; + private float zoom = -200f; + private float zoomText = 1f; + private int currentText = 0; + + private Label[] labels = null; + private String[] strings = null; + private UIRegion[] labelRegions; + private UIRegion fpsRegion = null; + private UIRegion jogampRegion = null; + private RIButton[] buttons = null; + + private int numSelectable = 6; + + private SceneUIController sceneUIController = null; + private MultiTouchListener multiTouchListener = null; + private boolean showFPS = false; + private GLAutoDrawable cDrawable; + private float fps = 0; + + private String jogamp = "JogAmp - Jogl Graph Module Demo"; + private float angText = 0; + + public GPUUISceneGLListener0A() { + this(RenderState.createRenderState(new ShaderState(), SVertex.factory()), false, false); + } + + public GPUUISceneGLListener0A(RenderState rs, boolean debug, boolean trace) { + this.rs = rs; + + this.debug = debug; + this.trace = trace; + font = FontFactory.get(FontFactory.UBUNTU).getDefault(); + labelRegions = new UIRegion[3]; + } + + private void initButtons(int width, int height) { + buttons = new RIButton[numSelectable]; + int xaxis = -110; + float xSize = 40f; + float ySize = 16f; + + int start = 50; + int diff = (int)ySize + 5; + + buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){ + public void onClick() { + currentText = (currentText+1)%3; + } + public void onPressed() { } + public void onRelease() { } + }; + + buttons[0].setPosition(xaxis,start,0); + + buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){ + public void onClick() { + showFPS = !showFPS; + } + public void onPressed() { } + public void onRelease() { } + }; + buttons[1].setPosition(xaxis,start - diff,0); + buttons[1].setToggleable(true); + + buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){ + public void onClick() { + cDrawable.invoke(false, new GLRunnable() { + public boolean run(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + int i = gl.getSwapInterval(); + i = i==0 ? 1 : 0; + gl.setSwapInterval(i); + final GLAnimatorControl a = drawable.getAnimator(); + if( null != a ) { + a.resetFPSCounter(); + } + return true; + } + }); + } + public void onPressed() { } + public void onRelease() { } + }; + buttons[2].setPosition(xaxis,start-diff*2,0); + buttons[2].setToggleable(true); + + buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) { + public void onClick() { + ang+=10; + } + public void onPressed() { + + } + public void onRelease() { } + }; + buttons[3].setPosition(xaxis,start-diff*3,0); + + buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){ + public void onClick() { + ang-=10; + } + public void onPressed() { } + public void onRelease() { } + }; + buttons[4].setPosition(xaxis,start-diff*4,0); + + buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){ + public void onClick() { + cDrawable.destroy(); + } + public void onPressed() { } + public void onRelease() { } + }; + buttons[5].setPosition(xaxis,start-diff*5,0); + buttons[5].setButtonColor(0.8f, 0.0f, 0.0f); + buttons[5].setLabelColor(1.0f, 1.0f, 1.0f); + + buttons[5].setButtonSelectedColor(0.8f, 0.8f, 0.8f); + buttons[5].setLabelSelectedColor(0.8f, 0.0f, 0.0f); + } + + private void initTexts() { + strings = new String[3]; + + strings[0] = "abcdefghijklmn\nopqrstuvwxyz\nABCDEFGHIJKL\nMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; + strings[1] = "The quick brown fox\njumps over the lazy\ndog"; + + strings[2] = + "Lorem ipsum dolor sit amet, consectetur\n"+ + "Ut purus odio, rhoncus sit amet com\n"+ + "quam iaculis urna cursus ornare. Nullam\n"+ + "In hac habitasse platea dictumst. Vivam\n"+ + "Morbi quis bibendum nibh. Donec lectus\n"+ + "Donec ut dolor et nulla tristique variu\n"+ + "in lorem. Maecenas in ipsum ac justo sc\n"; + + labels = new Label[3]; + } + + public void init(GLAutoDrawable drawable) { + if(drawable instanceof GLWindow) { + final GLWindow glw = (GLWindow) drawable; + attachInputListenerTo(glw); + } + final int width = drawable.getWidth(); + final int height = drawable.getHeight(); + cDrawable = drawable; + GL2ES2 gl = drawable.getGL().getGL2ES2(); + if(debug) { + gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) ).getGL2ES2(); + } + if(trace) { + gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); + } + + this.font = FontFactory.get(fontSet).getDefault(); + regionRenderer = RegionRenderer.create(rs, 0); + + gl.setSwapInterval(1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + gl.glEnable(GL2ES2.GL_BLEND); + + regionRenderer.init(gl); + regionRenderer.setAlpha(gl, 1.0f); + regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + + initTexts(); + initButtons(width, height); + + sceneUIController.setRenderer(regionRenderer, rs); + sceneUIController.addShape(buttons[0]); + sceneUIController.addShape(buttons[1]); + sceneUIController.addShape(buttons[2]); + sceneUIController.addShape(buttons[3]); + sceneUIController.addShape(buttons[4]); + sceneUIController.addShape(buttons[5]); + + Label jlabel = new Label(SVertex.factory(), font, fontSizeFixed, jogamp){ + public void onClick() { } + public void onPressed() { } + public void onRelease() { } + }; + + jogampRegion = new UIRegion(jlabel); + } + + public void dispose(GLAutoDrawable drawable) { + if(drawable instanceof GLWindow) { + final GLWindow glw = (GLWindow) drawable; + detachInputListenerFrom(glw); + } + + GL2ES2 gl = drawable.getGL().getGL2ES2(); + sceneUIController = null; + regionRenderer.destroy(gl); + } + + public void display(GLAutoDrawable drawable) { + final int width = drawable.getWidth(); + final int height = drawable.getHeight(); + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + regionRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f); + sceneUIController.setTranslate(xTran, yTran, zoom); + sceneUIController.setRotation(0, ang, 0); + + renderScene(drawable); + } + + private void renderScene(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + regionRenderer.resetModelview(null); + regionRenderer.translate(null, xTran-50, yTran+43, zoom); + regionRenderer.translate(gl, 0, 30, 0); + regionRenderer.scale(null, zoomText, zoomText, 1); + regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f); + regionRenderer.rotate(gl, angText , 0, 1, 0); + regionRenderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f); + regionRenderer.draw(gl, jogampRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, 0); + + if(null == labelRegions[currentText]) { + if( null == labels[currentText]) { + labels[currentText] = new Label(SVertex.factory(), font, fontSizeFixed, strings[currentText]){ + public void onClick() { } + public void onPressed() { } + public void onRelease() { } + }; + } + labelRegions[currentText] = new UIRegion(labels[currentText]); + } + + regionRenderer.resetModelview(null); + regionRenderer.translate(null, xTran-50, yTran, zoom); + regionRenderer.translate(gl, 0, 30, 0); + regionRenderer.scale(null, zoomText, zoomText, 1); + regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f); + regionRenderer.rotate(gl, zoomText, 0, 1, 0); + + regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); + regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, rs, 0), new float[]{0,0,0}, 0); + + final GLAnimatorControl animator = drawable.getAnimator(); + final boolean _drawFPS = showFPS && null != animator; + + if(_drawFPS && fps != animator.getTotalFPS()) { + if(null != fpsRegion) { + fpsRegion.destroy(gl, rs); + } + fps = animator.getTotalFPS(); + final String fpsS = String.valueOf(fps); + final int fpsSp = fpsS.indexOf('.'); + + Label fpsLabel = new Label(SVertex.factory(), font, fontSizeFixed, fpsS.substring(0, fpsSp+2)+" fps"){ + public void onClick() { } + public void onPressed() { } + public void onRelease() { } + }; + fpsRegion = new UIRegion(fpsLabel); + } + if(showFPS && null != fpsRegion) { + regionRenderer.translate(gl, 0, -60, 0); + regionRenderer.scale(null, zoomText, zoomText, 1); + regionRenderer.draw(gl, fpsRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, 0); + } + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glViewport(x, y, width, height); + regionRenderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f); + } + + public void attachInputListenerTo(GLWindow window) { + if ( null == multiTouchListener ) { + multiTouchListener = new MultiTouchListener(); + window.addMouseListener(multiTouchListener); + sceneUIController = new SceneUIController(); + window.addGLEventListener(sceneUIController); + sceneUIController.attachInputListenerTo(window); + } + } + + public void detachInputListenerFrom(GLWindow window) { + if ( null != multiTouchListener ) { + window.removeMouseListener(multiTouchListener); + window.removeGLEventListener(sceneUIController); + sceneUIController.detachInputListenerFrom(window); + } + } + + private class MultiTouchListener extends MouseAdapter { + int lx = 0; + int ly = 0; + + boolean first = false; + + @Override + public void mousePressed(MouseEvent e) { + first = true; + } + + @Override + public void mouseReleased(MouseEvent e) { + first = false; + } + + @Override + public void mouseDragged(MouseEvent e) { + if(first) { + lx = e.getX(); + ly = e.getY(); + first=false; + return; + } + int dx = lx - e.getX(); + int dy = e.getY() - ly; + if(Math.abs(dx) < Math.abs(dy)) { + zoom += Math.signum(dy); + } else { + xTran += Math.signum(dx); + } + + lx = e.getX(); + ly = e.getY(); + } + } +} \ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java new file mode 100644 index 000000000..14276ce44 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java @@ -0,0 +1,49 @@ +package com.jogamp.opengl.test.junit.graph.demos; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import com.jogamp.graph.curve.opengl.RenderState; +import com.jogamp.graph.geom.opengl.SVertex; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.glsl.ShaderState; + +public class GPUUISceneNewtDemo01 { + static final boolean DEBUG = false; + static final boolean TRACE = false; + + public static void main(String[] args) { + GLProfile.initSingleton(true); + GLProfile glp = GLProfile.getGL2ES2(); + GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(4); + caps.setSampleBuffers(true); + caps.setNumSamples(4); + + final GLWindow window = GLWindow.create(caps); + window.setPosition(10, 10); + window.setSize(680, 480); + window.setTitle("GraphUI Newt Demo"); + + final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); + GPUUISceneGLListener0A textGLListener = new GPUUISceneGLListener0A(rs, DEBUG, TRACE); + window.addGLEventListener(textGLListener); + textGLListener.attachInputListenerTo(window); + + final Animator animator = new Animator(); + animator.setUpdateFPSFrames(10, null); + animator.add(window); + + window.addWindowListener(new WindowAdapter() { + public void windowDestroyed(WindowEvent e) { + animator.stop(); + } + }); + + window.setVisible(true); + animator.start(); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java deleted file mode 100644 index dc0bc68fd..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUGraphGLListenerMT.java +++ /dev/null @@ -1,377 +0,0 @@ -package com.jogamp.opengl.test.junit.graph.demos.mobile; - -import javax.media.opengl.FPSCounter; -import javax.media.opengl.GL; -import javax.media.opengl.GL2ES2; -import javax.media.opengl.GLAnimatorControl; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.GLPipelineFactory; -import javax.media.opengl.GLRunnable; - -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.geom.opengl.SVertex; -import com.jogamp.newt.event.MouseEvent; -import com.jogamp.newt.event.MouseListener; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.test.junit.graph.demos.ui.Label; -import com.jogamp.opengl.test.junit.graph.demos.ui.RIButton; -import com.jogamp.opengl.test.junit.graph.demos.ui.SceneUIController; -import com.jogamp.opengl.test.junit.graph.demos.ui.opengl.UIRegion; - -public class GPUGraphGLListenerMT implements GLEventListener { - - private boolean debug = false; - private boolean trace = false; - - private RegionRenderer regionRenderer; - private RenderState rs; - - int fontSet = FontFactory.UBUNTU; - Font font; - final int fontSizeFixed = 6; - - private float xTran = 0; - private float yTran = 0; - private float ang = 0f; - private float zoom = -200f; - private float zoomText = 1f; - private int currentText = 0; - - private Label[] labels = null; - private String[] strings = null; - private UIRegion[] labelRegions; - private UIRegion fpsRegion = null; - private UIRegion jogampRegion = null; - private RIButton[] buttons = null; - - private int numSelectable = 6; - - private int mouseX, mouseY; - private SceneUIController sceneUIController = null; - - private boolean showFPS = false; - private GLAutoDrawable cDrawable; - private float fps = 0; - - private String jogamp = "JogAmp - Jogl Graph Module Demo"; - private float angText = 0; - - public GPUGraphGLListenerMT(RenderState rs, boolean debug, boolean trace) { - this.rs = rs; - - this.debug = debug; - this.trace = trace; - font = FontFactory.get(FontFactory.UBUNTU).getDefault(); - labelRegions = new UIRegion[3]; - } - - private void initButtons(int width, int height) { - buttons = new RIButton[numSelectable]; - int xaxis = -110; - float xSize = 40f; - float ySize = 16f; - - int start = 50; - int diff = (int)ySize + 5; - - buttons[0] = new RIButton(SVertex.factory(), font, "Next Text", xSize, ySize){ - public void onClick() { - currentText = (currentText+1)%3; - } - public void onPressed() { } - public void onRelease() { } - }; - - buttons[0].setPosition(xaxis,start,0); - - buttons[1] = new RIButton(SVertex.factory(), font, "Show FPS", xSize, ySize){ - public void onClick() { - showFPS = !showFPS; - } - public void onPressed() { } - public void onRelease() { } - }; - buttons[1].setPosition(xaxis,start - diff,0); - buttons[1].setToggleable(true); - - buttons[2] = new RIButton(SVertex.factory(), font, "v-sync", xSize, ySize){ - public void onClick() { - cDrawable.invoke(false, new GLRunnable() { - public boolean run(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - int i = gl.getSwapInterval(); - i = i==0 ? 1 : 0; - gl.setSwapInterval(i); - final GLAnimatorControl a = drawable.getAnimator(); - if( null != a ) { - a.resetFPSCounter(); - } - return true; - } - }); - } - public void onPressed() { } - public void onRelease() { } - }; - buttons[2].setPosition(xaxis,start-diff*2,0); - buttons[2].setToggleable(true); - - buttons[3] = new RIButton(SVertex.factory(), font, "Tilt +Y", xSize, ySize) { - public void onClick() { - ang+=10; - } - public void onPressed() { - - } - public void onRelease() { } - }; - buttons[3].setPosition(xaxis,start-diff*3,0); - - buttons[4] = new RIButton(SVertex.factory(), font, "Tilt -Y", xSize, ySize){ - public void onClick() { - ang-=10; - } - public void onPressed() { } - public void onRelease() { } - }; - buttons[4].setPosition(xaxis,start-diff*4,0); - - buttons[5] = new RIButton(SVertex.factory(), font, "Quit", xSize, ySize){ - public void onClick() { - cDrawable.destroy(); - } - public void onPressed() { } - public void onRelease() { } - }; - buttons[5].setPosition(xaxis,start-diff*5,0); - buttons[5].setButtonColor(0.8f, 0.0f, 0.0f); - buttons[5].setLabelColor(1.0f, 1.0f, 1.0f); - - buttons[5].setButtonSelectedColor(0.8f, 0.8f, 0.8f); - buttons[5].setLabelSelectedColor(0.8f, 0.0f, 0.0f); - } - - private void initTexts() { - strings = new String[3]; - - strings[0] = "abcdefghijklmn\nopqrstuvwxyz\nABCDEFGHIJKL\nMNOPQRSTUVWXYZ\n0123456789.:,;(*!?/\\\")$%^&-+@~#<>{}[]"; - strings[1] = "The quick brown fox\njumps over the lazy\ndog"; - - strings[2] = - "Lorem ipsum dolor sit amet, consectetur\n"+ - "Ut purus odio, rhoncus sit amet com\n"+ - "quam iaculis urna cursus ornare. Nullam\n"+ - "In hac habitasse platea dictumst. Vivam\n"+ - "Morbi quis bibendum nibh. Donec lectus\n"+ - "Donec ut dolor et nulla tristique variu\n"+ - "in lorem. Maecenas in ipsum ac justo sc\n"; - - labels = new Label[3]; - } - - @Override - public void init(GLAutoDrawable drawable) { - final int width = drawable.getWidth(); - final int height = drawable.getHeight(); - cDrawable = drawable; - GL2ES2 gl = drawable.getGL().getGL2ES2(); - if(debug) { - gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, gl, null) ).getGL2ES2(); - } - if(trace) { - gl = gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, gl, new Object[] { System.err } ) ).getGL2ES2(); - } - - this.font = FontFactory.get(fontSet).getDefault(); - regionRenderer = RegionRenderer.create(rs, 0); - - gl.setSwapInterval(1); - gl.glEnable(GL2ES2.GL_DEPTH_TEST); - gl.glEnable(GL2ES2.GL_BLEND); - - regionRenderer.init(gl); - regionRenderer.setAlpha(gl, 1.0f); - regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - - initTexts(); - initButtons(width, height); - - sceneUIController.setRenderer(regionRenderer, rs); - sceneUIController.addShape(buttons[0]); - sceneUIController.addShape(buttons[1]); - sceneUIController.addShape(buttons[2]); - sceneUIController.addShape(buttons[3]); - sceneUIController.addShape(buttons[4]); - sceneUIController.addShape(buttons[5]); - - Label jlabel = new Label(SVertex.factory(), font, fontSizeFixed, jogamp){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - - jogampRegion = new UIRegion(jlabel); - } - - @Override - public void dispose(GLAutoDrawable drawable) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - sceneUIController = null; - regionRenderer.destroy(gl); - } - - @Override - public void display(GLAutoDrawable drawable) { - final int width = drawable.getWidth(); - final int height = drawable.getHeight(); - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - regionRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f); - sceneUIController.setTranslate(xTran, yTran, zoom); - sceneUIController.setRotation(0, ang, 0); - - renderScene(drawable); - } - - private void renderScene(GLAutoDrawable drawable) { - final int width = drawable.getWidth(); - final int height = drawable.getHeight(); - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - regionRenderer.resetModelview(null); - regionRenderer.translate(null, xTran-50, yTran+43, zoom); - regionRenderer.translate(gl, 0, 30, 0); - regionRenderer.scale(null, zoomText, zoomText, 1); - regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f); - regionRenderer.rotate(gl, angText , 0, 1, 0); - regionRenderer.setColorStatic(gl, 0.0f, 1.0f, 0.0f); - regionRenderer.draw(gl, jogampRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, 0); - - if(null == labelRegions[currentText]) { - if( null == labels[currentText]) { - labels[currentText] = new Label(SVertex.factory(), font, fontSizeFixed, strings[currentText]){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - } - labelRegions[currentText] = new UIRegion(labels[currentText]); - } - - regionRenderer.resetModelview(null); - regionRenderer.translate(null, xTran-50, yTran, zoom); - regionRenderer.translate(gl, 0, 30, 0); - regionRenderer.scale(null, zoomText, zoomText, 1); - regionRenderer.scale(gl, 1.5f, 1.5f, 1.0f); - regionRenderer.rotate(gl, zoomText, 0, 1, 0); - - regionRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f); - regionRenderer.draw(gl, labelRegions[currentText].getRegion(gl, rs, 0), new float[]{0,0,0}, 0); - - final GLAnimatorControl animator = drawable.getAnimator(); - final boolean _drawFPS = showFPS && null != animator; - - if(_drawFPS && fps != animator.getTotalFPS()) { - if(null != fpsRegion) { - fpsRegion.destroy(gl, rs); - } - fps = animator.getTotalFPS(); - final String fpsS = String.valueOf(fps); - final int fpsSp = fpsS.indexOf('.'); - - Label fpsLabel = new Label(SVertex.factory(), font, fontSizeFixed, fpsS.substring(0, fpsSp+2)+" fps"){ - public void onClick() { } - public void onPressed() { } - public void onRelease() { } - }; - fpsRegion = new UIRegion(fpsLabel); - } - if(showFPS && null != fpsRegion) { - regionRenderer.translate(gl, 0, -60, 0); - regionRenderer.scale(null, zoomText, zoomText, 1); - regionRenderer.draw(gl, fpsRegion.getRegion(gl, rs, 0), new float[]{0,0,0}, 0); - } - } - - @Override - public void reshape(GLAutoDrawable drawable, int x, int y, int width, - int height) { - GL2ES2 gl = drawable.getGL().getGL2ES2(); - - gl.glViewport(x, y, width, height); - regionRenderer.reshapePerspective(gl, 45.0f, width, height, 5f, 70.0f); - } - - public void attachInputListenerTo(GLWindow window) { - MultiTouchListener multiTouchListener = new MultiTouchListener(); - window.addMouseListener(multiTouchListener); - sceneUIController = new SceneUIController(); - window.addGLEventListener(sceneUIController); - sceneUIController.attachInputListenerTo(window); - } - - private class MultiTouchListener implements MouseListener { - int lx = 0; - int ly = 0; - - boolean first = false; - @Override - public void mouseClicked(MouseEvent e) { - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } - - @Override - public void mousePressed(MouseEvent e) { - first = true; - } - - @Override - public void mouseReleased(MouseEvent e) { - first = false; - } - - @Override - public void mouseMoved(MouseEvent e) { - - } - - @Override - public void mouseDragged(MouseEvent e) { - if(first) { - lx = e.getX(); - ly = e.getY(); - first=false; - return; - } - int dx = lx - e.getX(); - int dy = e.getY() - ly; - if(Math.abs(dx) < Math.abs(dy)) { - zoom += Math.signum(dy); - } else { - xTran += Math.signum(dx); - } - - lx = e.getX(); - ly = e.getY(); - } - - @Override - public void mouseWheelMoved(MouseEvent e) { - - } - } -} \ No newline at end of file diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java deleted file mode 100644 index 66f709595..000000000 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/mobile/GPUTextNewtDemoMobile01.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.jogamp.opengl.test.junit.graph.demos.mobile; - -import javax.media.opengl.GLCapabilities; -import javax.media.opengl.GLProfile; - -import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.graph.geom.opengl.SVertex; -import com.jogamp.newt.event.WindowAdapter; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.glsl.ShaderState; - -public class GPUTextNewtDemoMobile01 { - static final boolean DEBUG = false; - static final boolean TRACE = false; - - public static void main(String[] args) { - GLProfile.initSingleton(true); - GLProfile glp = GLProfile.getGL2ES2(); - GLCapabilities caps = new GLCapabilities(glp); - caps.setAlphaBits(4); - caps.setSampleBuffers(true); - caps.setNumSamples(4); - - final GLWindow window = GLWindow.create(caps); - window.setPosition(10, 10); - window.setSize(680, 480); - window.setTitle("GraphUI Newt Demo"); - - final RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory()); - GPUGraphGLListenerMT textGLListener = new GPUGraphGLListenerMT(rs, DEBUG, TRACE); - window.addGLEventListener(textGLListener); - textGLListener.attachInputListenerTo(window); - - final Animator animator = new Animator(); - animator.setUpdateFPSFrames(10, null); - animator.add(window); - - window.addWindowListener(new WindowAdapter() { - public void windowDestroyed(WindowEvent e) { - animator.stop(); - } - }); - - window.setVisible(true); - animator.start(); - } -} 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 d3b1de827..9ee1c519e 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 @@ -52,10 +52,18 @@ public class SceneUIController implements GLEventListener{ } public void attachInputListenerTo(GLWindow window) { - sbcMouseListener = new SBCMouseListener();; - window.addMouseListener(sbcMouseListener); + if(null == sbcMouseListener) { + sbcMouseListener = new SBCMouseListener(); + window.addMouseListener(sbcMouseListener); + } } + public void detachInputListenerFrom(GLWindow window) { + if(null != sbcMouseListener) { + window.removeMouseListener(sbcMouseListener); + } + } + public ArrayList getShapes() { return shapes; } @@ -187,9 +195,6 @@ public class SceneUIController implements GLEventListener{ } private class SBCMouseListener implements MouseListener { - int lx = 0; - int ly = 0; - boolean selection = false; int mouseX = -1; int mouseY = -1; @@ -201,7 +206,6 @@ public class SceneUIController implements GLEventListener{ } public void mousePressed(MouseEvent e) { - selection = true; mouseX = e.getX(); mouseY = e.getY(); -- cgit v1.2.3