diff options
Diffstat (limited to 'src')
4 files changed, 61 insertions, 15 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 0484b6a77..8d1c708af 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 @@ -71,6 +71,12 @@ public class RedSquareES1 implements GLEventListener { } catch (Exception e) {e.printStackTrace();} } + System.err.println(Thread.currentThread()+"Chosen GLCapabilities: " + drawable.getChosenGLCapabilities()); + System.err.println(Thread.currentThread()+"INIT GL IS: " + gl.getClass().getName()); + System.err.println(Thread.currentThread()+"GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); + System.err.println(Thread.currentThread()+"GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); + System.err.println(Thread.currentThread()+"GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); + System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile()); System.err.println(Thread.currentThread()+" GL:" + gl); System.err.println(Thread.currentThread()+" GL_VERSION=" + gl.glGetString(GL.GL_VERSION)); 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 d0eb3b183..9bff38fce 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 @@ -56,7 +56,9 @@ public class GearsES2 implements GLEventListener { private GearsObjectES2 gear1=null, gear2=null, gear3=null; private float angle = 0.0f; private int swapInterval = 0; - private boolean initialized = false; + // private MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); + private MouseListener gearsMouse = new GearsMouseAdapter(); + private KeyListener gearsKeys = new GearsKeyAdapter(); private int prevMouseX, prevMouseY; @@ -92,7 +94,6 @@ public class GearsES2 implements GLEventListener { public void init(GLAutoDrawable drawable) { System.err.println(Thread.currentThread()+" GearsES2.init ..."); - initialized = true; GL2ES2 gl = drawable.getGL().getGL2ES2(); System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities()); @@ -156,10 +157,6 @@ public class GearsES2 implements GLEventListener { System.err.println("gear3 reused: "+gear3); } - // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); - MouseListener gearsMouse = new GearsMouseAdapter(); - KeyListener gearsKeys = new GearsKeyAdapter(); - if (drawable instanceof Window) { Window window = (Window) drawable; window.addMouseListener(gearsMouse); @@ -197,7 +194,11 @@ public class GearsES2 implements GLEventListener { public void dispose(GLAutoDrawable drawable) { System.err.println(Thread.currentThread()+" GearsES2.dispose ... "); - initialized = false; + if (drawable instanceof Window) { + Window window = (Window) drawable; + window.removeMouseListener(gearsMouse); + window.removeKeyListener(gearsKeys); + } GL2ES2 gl = drawable.getGL().getGL2ES2(); st.useProgram(gl, false); gear1.destroy(gl); 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 81c97d861..d06c6da97 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 @@ -27,6 +27,9 @@ */ package com.jogamp.opengl.test.junit.jogl.demos.es2; +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.glsl.ShaderCode; @@ -34,8 +37,10 @@ import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState; 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.GLRunnable; import javax.media.opengl.GLUniformData; public class RedSquareES2 implements GLEventListener { @@ -46,6 +51,8 @@ public class RedSquareES2 implements GLEventListener { GLArrayDataServer colors ; long t0; private int swapInterval = 0; + MyMouseAdapter myMouse = new MyMouseAdapter(); + GLWindow glWindow = null; public RedSquareES2(int swapInterval) { this.swapInterval = swapInterval; @@ -64,7 +71,6 @@ public class RedSquareES2 implements GLEventListener { System.err.println(Thread.currentThread()+"GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR)); System.err.println(Thread.currentThread()+"GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER)); System.err.println(Thread.currentThread()+"GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); - System.err.println(Thread.currentThread()+" GL Profile: "+gl.getGLProfile()); System.err.println(Thread.currentThread()+" GL:" + gl); @@ -104,8 +110,8 @@ public class RedSquareES2 implements GLEventListener { // Allocate Color Array colors= GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); - colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1); - colors.putf(0); colors.putf(0); colors.putf(1); colors.putf(1); + colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1); + colors.putf(0); colors.putf(0); colors.putf(1); colors.putf(1); colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1); colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1); colors.seal(gl, true); @@ -117,6 +123,10 @@ public class RedSquareES2 implements GLEventListener { gl.glEnable(GL2ES2.GL_DEPTH_TEST); st.useProgram(gl, false); + if (glad instanceof GLWindow) { + glWindow = (GLWindow) glad; + glWindow.addMouseListener(myMouse); + } t0 = System.currentTimeMillis(); System.err.println(Thread.currentThread()+" RedSquareES2.init FIN"); } @@ -124,7 +134,6 @@ public class RedSquareES2 implements GLEventListener { public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { System.err.println(Thread.currentThread()+" RedSquareES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval); GL2ES2 gl = glad.getGL().getGL2ES2(); - gl.setSwapInterval(swapInterval); st.useProgram(gl, true); // Set location in front of camera @@ -132,7 +141,7 @@ public class RedSquareES2 implements GLEventListener { pmvMatrix.glLoadIdentity(); pmvMatrix.gluPerspective(45.0F, (float) width / (float) height, 1.0F, 100.0F); //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); - gl.glUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); st.useProgram(gl, false); System.err.println(Thread.currentThread()+" RedSquareES2.reshape FIN"); } @@ -141,8 +150,8 @@ public class RedSquareES2 implements GLEventListener { long t1 = System.currentTimeMillis(); GL2ES2 gl = glad.getGL().getGL2ES2(); - st.useProgram(gl, true); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + st.useProgram(gl, true); // One rotation every four seconds pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); @@ -150,7 +159,8 @@ public class RedSquareES2 implements GLEventListener { float ang = ((float) (t1 - t0) * 360.0F) / 4000.0F; pmvMatrix.glRotatef(ang, 0, 0, 1); pmvMatrix.glRotatef(ang, 0, 1, 0); - gl.glUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); + // Draw a square vertices.enableBuffer(gl, true); colors.enableBuffer(gl, true); @@ -162,6 +172,10 @@ public class RedSquareES2 implements GLEventListener { public void dispose(GLAutoDrawable glad) { System.err.println(Thread.currentThread()+" RedSquareES2.dispose ... "); + if (null != glWindow) { + glWindow.removeMouseListener(myMouse); + glWindow = null; + } GL2ES2 gl = glad.getGL().getGL2ES2(); st.destroy(gl); st = null; @@ -169,4 +183,29 @@ public class RedSquareES2 implements GLEventListener { pmvMatrix = null; System.err.println(Thread.currentThread()+" RedSquareES2.dispose FIN"); } + + class MyMouseAdapter extends MouseAdapter { + public void mouseClicked(MouseEvent e) { + System.err.println(e); + if(null != glWindow && e.getSource() == glWindow.getWindow()) { + if(e.getX() < glWindow.getWidth()/2) { + glWindow.setFullscreen(!glWindow.isFullscreen()); + System.err.println("setFullscreen: "+glWindow.isFullscreen()); + } else { + glWindow.invoke(false, new GLRunnable() { + public boolean run(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + gl.setSwapInterval(gl.getSwapInterval()<=0?1:0); + System.err.println("setSwapInterval: "+gl.getSwapInterval()); + final GLAnimatorControl a = drawable.getAnimator(); + if( null != a ) { + a.resetFPSCounter(); + } + return true; + } + }); + } + } + } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java index b83bdb45d..63ec215fc 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java @@ -103,7 +103,7 @@ public class TestRedSquareES2NEWT extends UITestCase { glWindow.setSize(width, height); glWindow.setVisible(true); - animator.setUpdateFPSFrames(1, null); + animator.setUpdateFPSFrames(60, System.err); animator.start(); while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { |