diff options
Diffstat (limited to 'src')
51 files changed, 1292 insertions, 630 deletions
diff --git a/src/demos/GLNewtRun.java b/src/demos/GLNewtRun.java index 5310a93..d02657c 100755 --- a/src/demos/GLNewtRun.java +++ b/src/demos/GLNewtRun.java @@ -233,11 +233,11 @@ public class GLNewtRun extends WindowAdapter implements KeyListener, MouseListen window.setFullscreen(fullscreen); // Size OpenGL to Video Surface window.setVisible(true); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); do { window.display(); - } while (!quit && window.getDuration() < 20000) ; + } while (!quit && window.getTotalFPSDuration() < 20000) ; window.destroy(); diff --git a/src/demos/applets/JOGLNewtApplet1Run.java b/src/demos/applets/JOGLNewtApplet1Run.java deleted file mode 100755 index 0a5311b..0000000 --- a/src/demos/applets/JOGLNewtApplet1Run.java +++ /dev/null @@ -1,93 +0,0 @@ -package demos.applets; - -import java.applet.*; -import java.awt.Container; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.KeyListener; - -import javax.media.opengl.*; -import com.jogamp.newt.awt.NewtCanvasAWT; -import com.jogamp.newt.opengl.GLWindow; -import java.awt.BorderLayout; - -/** Shows how to deploy an applet using JOGL. This demo must be - referenced from a web page via an <applet> tag. */ - -public class JOGLNewtApplet1Run extends Applet { - GLWindow glWindow; - NewtCanvasAWT newtCanvasAWT; - JOGLNewtAppletBase base; - - public void init() { - if(!(this instanceof Container)) { - throw new RuntimeException("This Applet is not a AWT Container"); - } - Container container = (Container) this; // have to think about that, we may use a Container - - String glEventListenerClazzName=null; - String glProfileName=null; - int glSwapInterval=0; - boolean glDebug=false; - boolean glTrace=false; - String tmp; - try { - glEventListenerClazzName = getParameter("gl_event_listener_class"); - glProfileName = getParameter("gl_profile"); - glSwapInterval = JOGLNewtAppletBase.str2Int(getParameter("gl_swap_interval"), glSwapInterval); - glDebug = JOGLNewtAppletBase.str2Bool(getParameter("gl_debug"), glDebug); - glTrace = JOGLNewtAppletBase.str2Bool(getParameter("gl_trace"), glTrace); - } catch (Exception e) { - e.printStackTrace(); - } - if(null==glEventListenerClazzName) { - throw new RuntimeException("No applet parameter 'gl_event_listener_class'"); - } - base = new JOGLNewtAppletBase(glEventListenerClazzName, - glSwapInterval, - glDebug, - glTrace); - - try { - GLProfile.initSingleton(false); - GLCapabilities caps = new GLCapabilities(GLProfile.get(glProfileName)); - glWindow = GLWindow.create(caps); - newtCanvasAWT = new NewtCanvasAWT(glWindow); - container.setLayout(new BorderLayout()); - container.add(newtCanvasAWT, BorderLayout.CENTER); - base.init(glWindow); - if(base.isValid()) { - GLEventListener glEventListener = base.getGLEventListener(); - - if(glEventListener instanceof MouseListener) { - addMouseListener((MouseListener)glEventListener); - } - if(glEventListener instanceof MouseMotionListener) { - addMouseMotionListener((MouseMotionListener)glEventListener); - } - if(glEventListener instanceof KeyListener) { - addKeyListener((KeyListener)glEventListener); - } - } - } catch (Throwable t) { - throw new RuntimeException(t); - } - } - - public void start() { - base.start(); - } - - public void stop() { - base.stop(); - } - - public void destroy() { - glWindow.setVisible(false); // hide 1st - glWindow.reparentWindow(null); // get out of newtCanvasAWT - this.remove(newtCanvasAWT); // remove newtCanvasAWT - base.destroy(); // destroy glWindow unrecoverable - base=null; - } -} - diff --git a/src/demos/applets/JOGLNewtAppletBase.java b/src/demos/applets/JOGLNewtAppletBase.java deleted file mode 100755 index 9fa1bdc..0000000 --- a/src/demos/applets/JOGLNewtAppletBase.java +++ /dev/null @@ -1,243 +0,0 @@ -package demos.applets; - -import java.lang.reflect.*; - -import javax.media.nativewindow.NativeWindow; -import javax.media.opengl.*; -import com.jogamp.opengl.util.*; - -import com.jogamp.newt.event.*; -import com.jogamp.newt.opengl.GLWindow; - -/** Shows how to deploy an applet using JOGL. This demo must be - referenced from a web page via an <applet> tag. */ - -public class JOGLNewtAppletBase extends WindowAdapter implements KeyListener, MouseListener, GLEventListener { - String glEventListenerClazzName; - int glSwapInterval; - boolean glDebug; - boolean glTrace; - - GLEventListener glEventListener = null; - GLWindow glWindow = null; - Animator glAnimator=null; - boolean isValid = false; - NativeWindow awtParent; - - public JOGLNewtAppletBase(String glEventListenerClazzName, - int glSwapInterval, - boolean glDebug, - boolean glTrace) { - - this.glEventListenerClazzName=glEventListenerClazzName; - this.glSwapInterval=glSwapInterval; - this.glDebug = glDebug; - this.glTrace = glTrace; - } - - public GLEventListener getGLEventListener() { return glEventListener; } - public GLWindow getGLWindow() { return glWindow; } - public Animator getGLAnimator() { return glAnimator; } - public boolean isValid() { return isValid; } - - public static boolean str2Bool(String str, boolean def) { - if(null==str) return def; - try { - return Boolean.valueOf(str).booleanValue(); - } catch (Exception ex) { ex.printStackTrace(); } - return def; - } - - public static int str2Int(String str, int def) { - if(null==str) return def; - try { - return Integer.parseInt(str); - } catch (Exception ex) { ex.printStackTrace(); } - return def; - } - - public static GLEventListener createInstance(String clazzName) { - Object instance = null; - - try { - Class clazz = Class.forName(clazzName); - instance = clazz.newInstance(); - } catch (Throwable t) { - t.printStackTrace(); - throw new RuntimeException("Error while instantiating demo: "+clazzName); - } - if( null == instance ) { - throw new RuntimeException("Null GLEventListener: "+clazzName); - } - if( !(instance instanceof GLEventListener) ) { - throw new RuntimeException("Not a GLEventListener: "+clazzName); - } - return (GLEventListener) instance; - } - - public static boolean setField(Object instance, String fieldName, Object value) { - try { - Field f = instance.getClass().getField(fieldName); - if(f.getType().isInstance(value)) { - f.set(instance, value); - return true; - } else { - System.out.println(instance.getClass()+" '"+fieldName+"' field not assignable with "+value.getClass()+", it's a: "+f.getType()); - } - } catch (NoSuchFieldException nsfe) { - System.out.println(instance.getClass()+" has no '"+fieldName+"' field"); - } catch (Throwable t) { - t.printStackTrace(); - } - return false; - } - - public void init(GLWindow glWindow) { - init(Thread.currentThread().getThreadGroup(), glWindow); - } - - public void init(ThreadGroup tg, GLWindow glWindow) { - this.glWindow = glWindow; - - glEventListener = createInstance(glEventListenerClazzName); - - try { - if(!setField(glEventListener, "window", glWindow)) { - setField(glEventListener, "glWindow", glWindow); - } - - glWindow.addGLEventListener(this); - glWindow.addGLEventListener(glEventListener); - - if(glEventListener instanceof WindowListener) { - glWindow.addWindowListener((WindowListener)glEventListener); - } - glWindow.addWindowListener(this); - - if(glEventListener instanceof MouseListener) { - glWindow.addMouseListener((MouseListener)glEventListener); - } - glWindow.addMouseListener(this); - - if(glEventListener instanceof KeyListener) { - glWindow.addKeyListener((KeyListener)glEventListener); - } - glWindow.addKeyListener(this); - - glWindow.enablePerfLog(true); - - // glAnimator = new FPSAnimator(canvas, 60); - glAnimator = new Animator(tg, glWindow); - } catch (Throwable t) { - throw new RuntimeException(t); - } - isValid = true; - } - - public void start() { - if(isValid) { - glWindow.setVisible(true); - glAnimator.start(); - awtParent = glWindow.getParent(); - if(null==awtParent) { - throw new RuntimeException("Parent of GLWindow is null: "+glWindow); - } - } - } - - public void stop() { - if(null!=glAnimator) { - glAnimator.stop(); - glWindow.setVisible(false); - } - } - - public void destroy() { - isValid = false; - if(null!=glAnimator) { - glAnimator.stop(); - glAnimator.remove(glWindow); - glAnimator=null; - } - if(null!=glWindow) { - glWindow.destroy(); - glWindow=null; - } - } - - // *********************************************************************************** - // *********************************************************************************** - // *********************************************************************************** - - public void init(GLAutoDrawable drawable) { - GL _gl = drawable.getGL(); - - if(glDebug) { - try { - _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Debug", null, _gl, null) ); - } catch (Exception e) {e.printStackTrace();} - } - - if(glTrace) { - try { - // Trace .. - _gl = _gl.getContext().setGL( GLPipelineFactory.create("javax.media.opengl.Trace", null, _gl, new Object[] { System.err } ) ); - } catch (Exception e) {e.printStackTrace();} - } - - if(glSwapInterval>=0) { - _gl.setSwapInterval(glSwapInterval); - } - } - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - } - public void display(GLAutoDrawable drawable) { - } - public void dispose(GLAutoDrawable drawable) { - } - - // *********************************************************************************** - // *********************************************************************************** - // *********************************************************************************** - - public void keyPressed(KeyEvent e) { - } - public void keyReleased(KeyEvent e) { - } - public void keyTyped(KeyEvent e) { - if(e.getKeyChar()=='d') { - glWindow.setUndecorated(!glWindow.isUndecorated()); - } if(e.getKeyChar()=='f') { - glWindow.setFullscreen(!glWindow.isFullscreen()); - } else if(e.getKeyChar()=='r') { - if(null == glWindow.getParent()) { - glWindow.reparentWindow(awtParent); - } else { - glWindow.reparentWindow(null); - } - } - } - - // *********************************************************************************** - // *********************************************************************************** - // *********************************************************************************** - - public void mouseClicked(MouseEvent e) { - } - public void mouseEntered(MouseEvent e) { - } - public void mouseExited(MouseEvent e) { - } - public void mousePressed(MouseEvent e) { - } - public void mouseReleased(MouseEvent e) { - } - public void mouseMoved(MouseEvent e) { - } - public void mouseDragged(MouseEvent e) { - } - public void mouseWheelMoved(MouseEvent e) { - } - -} - diff --git a/src/demos/context/DualContext.java b/src/demos/context/DualContext.java index 562b1fd..318a399 100755 --- a/src/demos/context/DualContext.java +++ b/src/demos/context/DualContext.java @@ -167,6 +167,6 @@ public class DualContext extends Canvas { if (config == null) { return null; } - return config.getGraphicsConfiguration(); + return config.getAWTGraphicsConfiguration(); } } diff --git a/src/demos/cubefbo/FBCubes.java b/src/demos/cubefbo/FBCubes.java index 14aca21..765c37f 100755 --- a/src/demos/cubefbo/FBCubes.java +++ b/src/demos/cubefbo/FBCubes.java @@ -55,8 +55,8 @@ class FBCubes implements GLEventListener, MouseListener, MouseMotionListener { cubeInner = new CubeObject(false); cubeMiddle = new CubeObject(true); cubeOuter = new CubeObject(true); - fbo1 = new FBObject(FBO_SIZE, FBO_SIZE, 0); - fbo2 = new FBObject(FBO_SIZE, FBO_SIZE, 0); + fbo1 = new FBObject(FBO_SIZE, FBO_SIZE); + fbo2 = new FBObject(FBO_SIZE, FBO_SIZE); } public void init(GLAutoDrawable drawable) { @@ -64,7 +64,11 @@ class FBCubes implements GLEventListener, MouseListener, MouseMotionListener { // drawable.setGL(new DebugGL2(gl)); // gl = drawable.getGL().getGL2(); fbo1.init(gl); + fbo1.attachTexture2D(gl, 0, gl.GL_NEAREST, gl.GL_NEAREST, 0, 0); + fbo1.unbind(gl); fbo2.init(gl); + fbo2.attachTexture2D(gl, 0, gl.GL_NEAREST, gl.GL_NEAREST, 0, 0); + fbo2.unbind(gl); } int x, y, width, height; @@ -111,10 +115,10 @@ class FBCubes implements GLEventListener, MouseListener, MouseMotionListener { for (int i = 0; i < MAX_ITER; i++) { rend.bind(gl); gl.glEnable (GL.GL_TEXTURE_2D); - gl.glBindTexture(GL.GL_TEXTURE_2D, tex.getTextureName()); // to use it .. + tex.use(gl, 0); cubeMiddle.reshape(gl, 0, 0, FBO_SIZE, FBO_SIZE); cubeMiddle.display(gl, xRot, yRot); - gl.glBindTexture(GL.GL_TEXTURE_2D, 0); + tex.unuse(gl); gl.glDisable (GL.GL_TEXTURE_2D); rend.unbind(gl); FBObject tmp = tex; @@ -130,10 +134,10 @@ class FBCubes implements GLEventListener, MouseListener, MouseMotionListener { gl.glClearColor(0, 0, 0, 1); gl.glEnable (GL.GL_TEXTURE_2D); - gl.glBindTexture(GL.GL_TEXTURE_2D, tex.getTextureName()); // to use it .. + tex.use(gl, 0); cubeOuter.display(gl, xRot, yRot); // System.out.println("display .. p8"); - gl.glBindTexture(GL.GL_TEXTURE_2D, 0); + tex.unuse(gl); gl.glDisable (GL.GL_TEXTURE_2D); } diff --git a/src/demos/data/images/Stars.png b/src/demos/data/images/Stars.png Binary files differnew file mode 100644 index 0000000..49cec37 --- /dev/null +++ b/src/demos/data/images/Stars.png diff --git a/src/demos/data/images/TennisBottom.png b/src/demos/data/images/TennisBottom.png Binary files differnew file mode 100644 index 0000000..d712dd6 --- /dev/null +++ b/src/demos/data/images/TennisBottom.png diff --git a/src/demos/data/images/TennisEnDesk.png b/src/demos/data/images/TennisEnDesk.png Binary files differnew file mode 100644 index 0000000..d9c4306 --- /dev/null +++ b/src/demos/data/images/TennisEnDesk.png diff --git a/src/demos/data/images/TennisMyDesk.png b/src/demos/data/images/TennisMyDesk.png Binary files differnew file mode 100644 index 0000000..d4a3514 --- /dev/null +++ b/src/demos/data/images/TennisMyDesk.png diff --git a/src/demos/data/images/TennisTop.png b/src/demos/data/images/TennisTop.png Binary files differnew file mode 100644 index 0000000..c014744 --- /dev/null +++ b/src/demos/data/images/TennisTop.png diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 1049ee7..951eed0 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -131,12 +131,12 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.addKeyListener(this); window.addGLEventListener(this); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); // Size OpenGL to Video Surface window.setSize(width, height); // window.setFullscreen(true); window.setVisible(true); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); if(!oneThread) { if(useAnimator) { @@ -152,7 +152,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo } else { do { display(); - } while (!quit && window.getDuration() < 11000) ; + } while (!quit && window.getTotalFPSDuration() < 11000) ; shutdown(); } } @@ -213,7 +213,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo glTrace = false; } - GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(_gl); + GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl); if(swapInterval>=0) { gl.setSwapInterval(swapInterval); } @@ -284,7 +284,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -10); - float ang = ((float) window.getDuration() * 360.0f) / 4000.0f; + float ang = ((float) window.getTotalFPSDuration() * 360.0f) / 4000.0f; gl.glRotatef(ang, 0, 0, 1); gl.glRotatef(ang, 0, 1, 0); diff --git a/src/demos/es1/angeles/AngelesGL.java b/src/demos/es1/angeles/AngelesGL.java index bc367d7..42dbf76 100755 --- a/src/demos/es1/angeles/AngelesGL.java +++ b/src/demos/es1/angeles/AngelesGL.java @@ -86,7 +86,7 @@ public class AngelesGL implements GLEventListener { cComps = drawable.getGL().isGLES1() ? 4: 3; - this.gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL()); + this.gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL()); System.err.println("AngelesGL: "+this.gl); this.glu = GLU.createGLU(); @@ -298,14 +298,14 @@ public class GLSpatial { int[] tmp = new int[1]; gl.glGenBuffers(1, tmp, 0); vboName = tmp[0]; - - vArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, - 0, pBuffer, vboName, vOffset); - cArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, - 0, pBuffer, vboName, cOffset); + + vArrayData = GLArrayDataWrapper.createFixed(gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, + 0, pBuffer, vboName, vOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); + cArrayData = GLArrayDataWrapper.createFixed(gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, + 0, pBuffer, vboName, cOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); if(useNormalArray) { - nArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, - 0, pBuffer, vboName, nOffset); + nArrayData = GLArrayDataWrapper.createFixed(gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, + 0, pBuffer, vboName, nOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } } diff --git a/src/demos/es1/angeles/AngelesGLil.java b/src/demos/es1/angeles/AngelesGLil.java index 92be109..3e96dc1 100755 --- a/src/demos/es1/angeles/AngelesGLil.java +++ b/src/demos/es1/angeles/AngelesGLil.java @@ -82,7 +82,7 @@ public class AngelesGLil implements GLEventListener { cComps = drawable.getGL().isGLES1() ? 4: 3; - this.gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL()); + this.gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL()); System.err.println("AngelesGL: "+this.gl); this.glu = GLU.createGLU(); @@ -298,13 +298,13 @@ public class GLSpatial { interlArray.position(count*(vComps+cComps+nComps)); interlArray.flip(); - vArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, - bStride, pBuffer, vboName, vOffset); - cArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, - bStride, pBuffer, vboName, cOffset); + vArrayData = GLArrayDataWrapper.createFixed(gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, + bStride, pBuffer, vboName, vOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); + cArrayData = GLArrayDataWrapper.createFixed(gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, + bStride, pBuffer, vboName, cOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); if(useNormalArray) { - nArrayData = GLArrayDataWrapper.createFixed(gl, gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, - bStride, pBuffer, vboName, nOffset); + nArrayData = GLArrayDataWrapper.createFixed(gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, + bStride, pBuffer, vboName, nOffset, GL.GL_STATIC_DRAW, GL.GL_ARRAY_BUFFER); } } diff --git a/src/demos/es1/angeles/Main.java b/src/demos/es1/angeles/Main.java index 743f961..ad1a5b5 100755 --- a/src/demos/es1/angeles/Main.java +++ b/src/demos/es1/angeles/Main.java @@ -75,7 +75,7 @@ public class Main implements WindowListener, MouseListener { window.addWindowListener(this); window.addMouseListener(this); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setSize(width, height); window.setFullscreen(true); window.setVisible(true); @@ -97,7 +97,7 @@ public class Main implements WindowListener, MouseListener { } } - while (!quit && window.getDuration() < 215000) { + while (!quit && window.getTotalFPSDuration() < 215000) { window.display(); } diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java index fa88674..001f821 100644 --- a/src/demos/es1/cube/Cube.java +++ b/src/demos/es1/cube/Cube.java @@ -95,7 +95,7 @@ public class Cube implements GLEventListener { } catch (Exception e) {e.printStackTrace();} } - GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(_gl); + GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(_gl); glu = GLU.createGLU(); @@ -338,13 +338,13 @@ public class Cube implements GLEventListener { window.addGLEventListener(this); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); // Size OpenGL to Video Surface window.setSize(width, height); window.setFullscreen(true); window.setVisible(true); - while (!quit && window.getDuration() < 31000) { + while (!quit && window.getTotalFPSDuration() < 31000) { window.display(); } diff --git a/src/demos/es1/cube/CubeImmModeSink.java b/src/demos/es1/cube/CubeImmModeSink.java index a75b274..81f89d8 100644 --- a/src/demos/es1/cube/CubeImmModeSink.java +++ b/src/demos/es1/cube/CubeImmModeSink.java @@ -167,7 +167,7 @@ public class CubeImmModeSink implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL()); + GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL()); glu = GLU.createGLU(); @@ -403,7 +403,7 @@ public class CubeImmModeSink implements GLEventListener { window.addGLEventListener(this); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); // Size OpenGL to Video Surface window.setSize(width, height); window.setFullscreen(true); diff --git a/src/demos/es1/cubefbo/FBCubes.java b/src/demos/es1/cubefbo/FBCubes.java index b6a1b0d..b658798 100755 --- a/src/demos/es1/cubefbo/FBCubes.java +++ b/src/demos/es1/cubefbo/FBCubes.java @@ -45,7 +45,7 @@ public class FBCubes implements GLEventListener { public FBCubes () { cubeOuter = new Cube(true, false); - fbo1 = new FBObject(FBO_SIZE, FBO_SIZE, FBObject.ATTR_DEPTH); + fbo1 = new FBObject(FBO_SIZE, FBO_SIZE); cubeInner = new Cube(false, true); // JAU cubeMiddle = new Cube(true, false); @@ -53,7 +53,7 @@ public class FBCubes implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL()); + GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL()); System.out.println(gl); gl.glGetError(); // flush error .. @@ -73,10 +73,13 @@ public class FBCubes implements GLEventListener { }*/ fbo1.init(gl); - //fbo1.init(gl, GL.GL_RGB, GL.GL_RGB, GL.GL_UNSIGNED_BYTE); // faster - //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); // GLES2 default - //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1); // useless (1bit alpha) - //fbo1.init(gl, GL.GL_RGBA8, GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8_REV); // GL2 default + fbo1.attachTexture2D(gl, 0, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, 0, 0); + fbo1.attachDepthBuffer(gl, GL.GL_DEPTH_COMPONENT16); + //fbo1.init(gl, GL.GL_RGB, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, 0, 0); // faster + //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, 0, 0); // GLES2 default + //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, 0, 0); // useless (1bit alpha) + //fbo1.init(gl, GL.GL_RGBA8, GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8_REV, GL2ES2.GL_NEAREST, GL2ES2.GL_NEAREST, 0, 0); // GL2 default + fbo1.unbind(gl); cubeInner.init(drawable); cubeOuter.init(drawable); @@ -113,13 +116,11 @@ public class FBCubes implements GLEventListener { gl.glFinish(); fbo1.unbind(gl); - gl.glActiveTexture(GL.GL_TEXTURE0); gl.glEnable (gl.GL_TEXTURE_2D); + fbo1.use(gl, 0); cubeOuter.reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight()); - fbo1.use(gl); cubeOuter.display(drawable); - fbo1.unbind(gl); - + fbo1.unuse(gl); gl.glDisable (gl.GL_TEXTURE_2D); // JAUFBObject tex = fbo1; diff --git a/src/demos/es1/cubefbo/Main.java b/src/demos/es1/cubefbo/Main.java index cd26556..b2da7a5 100755 --- a/src/demos/es1/cubefbo/Main.java +++ b/src/demos/es1/cubefbo/Main.java @@ -76,7 +76,7 @@ public class Main implements WindowListener, MouseListener { window.addWindowListener(this); window.addMouseListener(this); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); window.setSize(width, height); window.setFullscreen(false); window.setVisible(true); @@ -85,7 +85,7 @@ public class Main implements WindowListener, MouseListener { FBCubes cubes = new FBCubes(); window.addGLEventListener(cubes); - while ( !quit && window.getDuration() < 31000) { + while ( !quit && window.getTotalFPSDuration() < 31000) { window.display(); } diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java index 1d0bcad..c335478 100755 --- a/src/demos/es2/RedSquare.java +++ b/src/demos/es2/RedSquare.java @@ -118,12 +118,12 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.setSize(width, height); // window.setFullscreen(true); window.setVisible(true); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); if(!oneThread) { do { display(); - } while (!quit && window.getDuration() < 20000) ; + } while (!quit && window.getTotalFPSDuration() < 20000) ; shutdown(); } @@ -212,18 +212,18 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo initShader(gl); // Push the 1st uniform down the path - st.glUseProgram(gl, true); + st.useProgram(gl, true); pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); - if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { + if(!st.uniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { throw new GLException("Error setting PMVMatrix in shader: "+st); } // Allocate vertex arrays - GLArrayDataClient vertices = GLArrayDataClient.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 4); + GLArrayDataClient vertices = GLArrayDataClient.createGLSL("mgl_Vertex", 3, gl.GL_FLOAT, false, 4); { // Fill them up FloatBuffer verticeb = (FloatBuffer)vertices.getBuffer(); @@ -234,7 +234,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo } vertices.seal(gl, true); - GLArrayDataClient colors = GLArrayDataClient.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 4); + GLArrayDataClient colors = GLArrayDataClient.createGLSL("mgl_Color", 4, gl.GL_FLOAT, false, 4); { // Fill them up FloatBuffer colorb = (FloatBuffer)colors.getBuffer(); @@ -249,7 +249,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo gl.glClearColor(0, 0, 0, 1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); - st.glUseProgram(gl, false); + st.useProgram(gl, false); // Let's show the completed shader state .. System.out.println(Thread.currentThread()+" "+st); @@ -260,7 +260,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo GL2ES2 gl = drawable.getGL().getGL2ES2(); - st.glUseProgram(gl, true); + st.useProgram(gl, true); // Set location in front of camera pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); @@ -271,10 +271,10 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo GLUniformData ud = st.getUniform("mgl_PMVMatrix"); if(null!=ud) { // same data object - st.glUniform(gl, ud); + st.uniform(gl, ud); } - st.glUseProgram(gl, false); + st.useProgram(gl, false); } public void dispose(GLAutoDrawable drawable) { @@ -295,7 +295,7 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo GL2ES2 gl = drawable.getGL().getGL2ES2(); - st.glUseProgram(gl, true); + st.useProgram(gl, true); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); @@ -303,20 +303,20 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); pmvMatrix.glTranslatef(0, 0, -10); - float ang = ((float) window.getDuration() * 360.0f) / 4000.0f; + float ang = ((float) window.getTotalFPSDuration() * 360.0f) / 4000.0f; pmvMatrix.glRotatef(ang, 0, 0, 1); pmvMatrix.glRotatef(ang, 0, 1, 0); GLUniformData ud = st.getUniform("mgl_PMVMatrix"); if(null!=ud) { // same data object - st.glUniform(gl, ud); + st.uniform(gl, ud); } // Draw a square gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); - st.glUseProgram(gl, false); + st.useProgram(gl, false); } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { diff --git a/src/demos/es2/openmax/Cube.java b/src/demos/es2/openmax/Cube.java index 5d318cf..51578dd 100644 --- a/src/demos/es2/openmax/Cube.java +++ b/src/demos/es2/openmax/Cube.java @@ -93,7 +93,7 @@ public class Cube implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL()); + GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL()); glu = GLU.createGLU(); @@ -330,13 +330,13 @@ public class Cube implements GLEventListener { window.addGLEventListener(this); - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); // Size OpenGL to Video Surface window.setSize(width, height); window.setFullscreen(true); window.setVisible(true); - while (!quit && window.getDuration() < 31000) { + while (!quit && window.getTotalFPSDuration() < 31000) { window.display(); } diff --git a/src/demos/es2/openmax/MovieCube.java b/src/demos/es2/openmax/MovieCube.java index 6b53c6d..932fcf8 100755 --- a/src/demos/es2/openmax/MovieCube.java +++ b/src/demos/es2/openmax/MovieCube.java @@ -122,7 +122,7 @@ public class MovieCube implements MouseListener, GLEventListener, OMXEventListen } public void init(GLAutoDrawable drawable) { - GL2ES1 gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL()); + GL2ES1 gl = FixedFuncUtil.wrapFixedFuncEmul(drawable.getGL()); System.out.println(gl); gl.glGetError(); // flush error .. @@ -185,13 +185,13 @@ public class MovieCube implements MouseListener, GLEventListener, OMXEventListen tex=movie.getNextTextureID(); if(null!=tex) { System.out.println("Use: "+tex); - tex.enable(); - tex.bind(); + tex.enable(gl); + tex.bind(gl); } } cube.display(drawable); if(null!=tex) { - tex.disable(); + tex.disable(gl); } } diff --git a/src/demos/es2/openmax/MovieSimple.java b/src/demos/es2/openmax/MovieSimple.java index 015d3b5..d6c8c7b 100755 --- a/src/demos/es2/openmax/MovieSimple.java +++ b/src/demos/es2/openmax/MovieSimple.java @@ -169,17 +169,17 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList initShader(gl); // Push the 1st uniform down the path - st.glUseProgram(gl, true); + st.useProgram(gl, true); pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); - if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { + if(!st.uniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { throw new GLException("Error setting PMVMatrix in shader: "+st); } - if(!st.glUniform(gl, new GLUniformData("mgl_ActiveTexture", 0))) { + if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", 0))) { throw new GLException("Error setting mgl_ActiveTexture in shader: "+st); } gl.glActiveTexture(GL.GL_TEXTURE0); @@ -197,7 +197,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList } // Allocate vertex array - GLArrayDataServer vertices = GLArrayDataServer.createGLSL(gl, "mgl_Vertex", 3, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); { // Fill them up FloatBuffer verticeb = (FloatBuffer)vertices.getBuffer(); @@ -209,7 +209,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList vertices.seal(gl, true); // Allocate texcoord array - GLArrayDataServer texcoord = GLArrayDataServer.createGLSL(gl, "mgl_MultiTexCoord", 2, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer texcoord = GLArrayDataServer.createGLSL("mgl_MultiTexCoord", 2, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); { // Fill them up FloatBuffer texcoordb = (FloatBuffer)texcoord.getBuffer(); @@ -220,7 +220,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList } texcoord.seal(gl, true); - GLArrayDataServer colors = GLArrayDataServer.createGLSL(gl, "mgl_Color", 4, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer colors = GLArrayDataServer.createGLSL("mgl_Color", 4, gl.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); { // Fill them up FloatBuffer colorb = (FloatBuffer)colors.getBuffer(); @@ -235,7 +235,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList gl.glClearColor(0.2f, 0.2f, 0.2f, 1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); - st.glUseProgram(gl, false); + st.useProgram(gl, false); // Let's show the completed shader state .. System.out.println(st); @@ -257,7 +257,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - st.glUseProgram(gl, true); + st.useProgram(gl, true); // Set location in front of camera pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); @@ -272,10 +272,10 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList GLUniformData ud = st.getUniform("mgl_PMVMatrix"); if(null!=ud) { // same data object - st.glUniform(gl, ud); + st.uniform(gl, ud); } - st.glUseProgram(gl, false); + st.useProgram(gl, false); } public void dispose(GLAutoDrawable drawable) { @@ -293,7 +293,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList public void display(GLAutoDrawable drawable) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - st.glUseProgram(gl, true); + st.useProgram(gl, true); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); @@ -312,7 +312,7 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList GLUniformData ud = st.getUniform("mgl_PMVMatrix"); if(null!=ud) { // same data object - st.glUniform(gl, ud); + st.uniform(gl, ud); } if(!rotate) { @@ -325,8 +325,8 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList if(null!=movie) { tex=movie.getNextTextureID(); if(null!=tex) { - tex.enable(); - tex.bind(); + tex.enable(gl); + tex.bind(gl); } } @@ -334,10 +334,10 @@ public class MovieSimple implements MouseListener, GLEventListener, OMXEventList gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); if(null!=tex) { - tex.disable(); + tex.disable(gl); } - st.glUseProgram(gl, false); + st.useProgram(gl, false); } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { diff --git a/src/demos/es2/perftst/PerfModule.java b/src/demos/es2/perftst/PerfModule.java index 69b9f1a..b472039 100644 --- a/src/demos/es2/perftst/PerfModule.java +++ b/src/demos/es2/perftst/PerfModule.java @@ -47,7 +47,7 @@ public abstract class PerfModule { // Let's manage all our states using ShaderState. st.attachShaderProgram(gl, sp); - st.glUseProgram(gl, true); + st.useProgram(gl, true); } public static final void put(Buffer buffer, int type, float v) { diff --git a/src/demos/es2/perftst/PerfTextLoad.java b/src/demos/es2/perftst/PerfTextLoad.java index 30f0ad7..f603796 100755 --- a/src/demos/es2/perftst/PerfTextLoad.java +++ b/src/demos/es2/perftst/PerfTextLoad.java @@ -1,5 +1,7 @@ package demos.es2.perftst; +import com.jogamp.common.util.IOUtil; + import java.nio.*; import java.io.*; import java.net.*; @@ -36,7 +38,7 @@ public class PerfTextLoad extends PerfModule { try { for(int i=0; i<numObjs; i++) { textName = "data/"+textBaseName+"."+(i+1)+".tga"; - URL urlText = Locator.getResource(Perftst.class, textName); + URL urlText = IOUtil.getResource(Perftst.class, textName); if(urlText==null) { throw new RuntimeException("couldn't fetch "+textName); } @@ -57,9 +59,9 @@ public class PerfTextLoad extends PerfModule { // Vertices Data setup // - st.glUseProgram(gl, true); + st.useProgram(gl, true); - GLArrayDataServer vertices = GLArrayDataServer.createGLSL(gl, "mgl_Vertex", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); { FloatBuffer vb = (FloatBuffer)vertices.getBuffer(); vb.put(0f); vb.put(0f); @@ -69,7 +71,7 @@ public class PerfTextLoad extends PerfModule { } vertices.seal(gl, true); - GLArrayDataServer texCoords = GLArrayDataServer.createGLSL(gl, "mgl_MultiTexCoord0", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer texCoords = GLArrayDataServer.createGLSL("mgl_MultiTexCoord0", 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); { FloatBuffer cb = (FloatBuffer)texCoords.getBuffer(); cb.put(0f); cb.put(0f); @@ -86,12 +88,12 @@ public class PerfTextLoad extends PerfModule { tU[0] = System.currentTimeMillis(); for(int j=0; j<numTextures; j++) { gl.glActiveTexture(j); - textures[j].updateImage(textDatas[0]); + textures[j].updateImage(gl, textDatas[0]); tU[j+1] = System.currentTimeMillis(); } GLUniformData activeTexture = new GLUniformData("mgl_ActiveTexture", 0); - st.glUniform(gl, activeTexture); + st.uniform(gl, activeTexture); // // run loops @@ -116,18 +118,18 @@ public class PerfTextLoad extends PerfModule { for(int k=0; k<numTextures; k++) { gl.glActiveTexture(GL.GL_TEXTURE0+k); - textures[k].enable(); - textures[k].bind(); + textures[k].enable(gl); + textures[k].bind(gl); activeTexture.setData(k); - st.glUniform(gl, activeTexture); + st.uniform(gl, activeTexture); t1[i][j][k] = System.currentTimeMillis(); - textures[k].updateSubImage(textDatas[j], 0, 0, 0); + textures[k].updateSubImage(gl, textDatas[j], 0, 0, 0); t2[i][j][k] = System.currentTimeMillis(); - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, vertices.getElementNumber()); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, vertices.getElementCount()); t3[i][j][k] = System.currentTimeMillis(); } @@ -189,11 +191,11 @@ public class PerfTextLoad extends PerfModule { } System.out.println("*****************************************************************"); - st.glUseProgram(gl, false); + st.useProgram(gl, false); for(int i=0; i<numTextures; i++) { - textures[i].disable(); - textures[i].dispose(); + textures[i].disable(gl); + textures[i].destroy(gl); textures[i]=null; } for(int i=0; i<numObjs; i++) { diff --git a/src/demos/es2/perftst/PerfUniLoad.java b/src/demos/es2/perftst/PerfUniLoad.java index 1c71253..92626b0 100755 --- a/src/demos/es2/perftst/PerfUniLoad.java +++ b/src/demos/es2/perftst/PerfUniLoad.java @@ -35,9 +35,9 @@ public class PerfUniLoad extends PerfModule { throw new GLException("numArrayElem must be within 0.."+MAX_ARRAY_ELEM); } - st.glUseProgram(gl, true); + st.useProgram(gl, true); - GLArrayDataServer vertices = GLArrayDataServer.createGLSL(gl, "mgl_Vertex", 3, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); { FloatBuffer vb = (FloatBuffer)vertices.getBuffer(); vb.put(0f); vb.put(0f); vb.put(0f); @@ -47,7 +47,7 @@ public class PerfUniLoad extends PerfModule { } vertices.seal(gl, true); - GLArrayDataServer colors = GLArrayDataServer.createGLSL(gl, "mgl_Color", 4, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + GLArrayDataServer colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); { FloatBuffer cb = (FloatBuffer)colors.getBuffer(); cb.put(0f); cb.put(0f); cb.put(0f); cb.put(1f); @@ -103,11 +103,11 @@ public class PerfUniLoad extends PerfModule { t0[i] = System.currentTimeMillis(); for(int j=0; j<numObjs; j++) { - st.glUniform(gl, dummyUni[j]); + st.uniform(gl, dummyUni[j]); t1[i][j] = System.currentTimeMillis(); - gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices.getElementNumber()); + gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices.getElementCount()); t2[i][j] = System.currentTimeMillis(); } @@ -155,7 +155,7 @@ public class PerfUniLoad extends PerfModule { System.out.println("*****************************************************************"); - st.glUseProgram(gl, false); + st.useProgram(gl, false); try { Thread.sleep(100); diff --git a/src/demos/es2/perftst/PerfVBOLoad.java b/src/demos/es2/perftst/PerfVBOLoad.java index d0b4a1d..8e73197 100755 --- a/src/demos/es2/perftst/PerfVBOLoad.java +++ b/src/demos/es2/perftst/PerfVBOLoad.java @@ -28,8 +28,8 @@ public class PerfVBOLoad extends PerfModule { float r=1f, g=1f, b=1f; for(int i=0; i<numObjs; i++) { - vertices[i] = GLArrayDataServer.createGLSL(gl, "mgl_Vertex", 3, dataType, true, numVertices, GL.GL_STATIC_DRAW); - vertices[i].setVBOUsage(useVBO); + vertices[i] = GLArrayDataServer.createGLSL("mgl_Vertex", 3, dataType, true, numVertices, GL.GL_STATIC_DRAW); + vertices[i].setVBOEnabled(useVBO); { Buffer verticeb = vertices[i].getBuffer(); for(int j=0; j<numVertices; j++) { @@ -42,8 +42,8 @@ public class PerfVBOLoad extends PerfModule { if(y>1f) { x=0f; y=0f; z+=0.01f; } } } - colors[i] = GLArrayDataServer.createGLSL(gl, "mgl_Color", 4, dataType, true, numVertices, GL.GL_STATIC_DRAW); - colors[i].setVBOUsage(useVBO); + colors[i] = GLArrayDataServer.createGLSL("mgl_Color", 4, dataType, true, numVertices, GL.GL_STATIC_DRAW); + colors[i].setVBOEnabled(useVBO); { // Fill them up Buffer colorb = colors[i].getBuffer(); @@ -74,7 +74,7 @@ public class PerfVBOLoad extends PerfModule { long[] tS = new long[loops]; // Push the 1st uniform down the path - st.glUseProgram(gl, true); + st.useProgram(gl, true); for(int i=0; i<loops; i++) { tC[i] = System.currentTimeMillis(); @@ -103,7 +103,7 @@ public class PerfVBOLoad extends PerfModule { t2[i][j] = System.currentTimeMillis(); - gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices[j].getElementNumber()); + gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertices[j].getElementCount()); if(numObjs>1) { vertices[j].enableBuffer(gl, false); @@ -127,10 +127,10 @@ public class PerfVBOLoad extends PerfModule { colors[0].enableBuffer(gl, false); } - int verticesElements = vertices[0].getElementNumber() * numObjs; - int verticesBytes = verticesElements * vertices[0].getComponentSize()* vertices[0].getComponentNumber(); - int colorsElements = colors[0].getElementNumber() * colors.length; - int colorsBytes = colorsElements * colors[0].getComponentSize()* colors[0].getComponentNumber(); + int verticesElements = vertices[0].getElementCount() * numObjs; + int verticesBytes = verticesElements * vertices[0].getComponentSizeInBytes()* vertices[0].getComponentCount(); + int colorsElements = colors[0].getElementCount() * colors.length; + int colorsBytes = colorsElements * colors[0].getComponentSizeInBytes()* colors[0].getComponentCount(); dt = 0; for(int i=1; i<loops; i++) { @@ -139,8 +139,8 @@ public class PerfVBOLoad extends PerfModule { System.out.println(""); System.out.println("Loops "+loops+", useVBO "+useVBO+", objects "+numObjs+", type "+getTypeName(dataType)+ - ", vertices p.o. "+vertices[0].getElementNumber()+ - ", colors p.o. "+colors[0].getElementNumber()+ + ", vertices p.o. "+vertices[0].getElementCount()+ + ", colors p.o. "+colors[0].getElementCount()+ ",\n total elements "+(verticesElements+colorsElements)+ ", total bytes "+(verticesBytes+colorsBytes)+", total time: "+dt + "ms, fps(-1): "+(((loops-1)*1000)/dt)+ @@ -164,7 +164,7 @@ public class PerfVBOLoad extends PerfModule { } System.out.println("*****************************************************************"); - st.glUseProgram(gl, false); + st.useProgram(gl, false); for(int i=0; i<numObjs; i++) { vertices[i].destroy(gl); diff --git a/src/demos/es2/perftst/Perftst.java b/src/demos/es2/perftst/Perftst.java index 4860e51..dba9e48 100755 --- a/src/demos/es2/perftst/Perftst.java +++ b/src/demos/es2/perftst/Perftst.java @@ -93,17 +93,17 @@ public class Perftst implements MouseListener, GLEventListener { pmvMatrix = new PMVMatrix(); pmod.initShaderState(gl); - st = ShaderState.getCurrent(); + st = ShaderState.getShaderState(gl); // Push the 1st uniform down the path - st.glUseProgram(gl, true); + st.useProgram(gl, true); pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); - if(!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { + if(!st.uniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) { throw new GLException("Error setting PMVMatrix in shader: "+st); } @@ -111,7 +111,7 @@ public class Perftst implements MouseListener, GLEventListener { gl.glClearColor(0, 0, 0, 1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); - st.glUseProgram(gl, false); + st.useProgram(gl, false); // Let's show the completed shader state .. System.out.println(st); @@ -120,7 +120,7 @@ public class Perftst implements MouseListener, GLEventListener { public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2ES2 gl = drawable.getGL().getGL2ES2(); - st.glUseProgram(gl, true); + st.useProgram(gl, true); // Set location in front of camera pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION); @@ -134,10 +134,10 @@ public class Perftst implements MouseListener, GLEventListener { GLUniformData ud = st.getUniform("mgl_PMVMatrix"); if(null!=ud) { // same data object - st.glUniform(gl, ud); + st.uniform(gl, ud); } - st.glUseProgram(gl, false); + st.useProgram(gl, false); } public void dispose(GLAutoDrawable drawable) { diff --git a/src/demos/gears/Gears.java b/src/demos/gears/Gears.java index 589ef8e..4b1b7f9 100644 --- a/src/demos/gears/Gears.java +++ b/src/demos/gears/Gears.java @@ -1,34 +1,38 @@ package demos.gears; -import javax.media.opengl.*; -import javax.media.opengl.awt.*; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; import com.jogamp.opengl.util.Animator; -import com.jogamp.newt.event.*; -import com.jogamp.newt.event.awt.*; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Frame; import com.jogamp.newt.Window; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.KeyListener; +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; +import com.jogamp.newt.event.MouseListener; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTMouseAdapter; /** * Gears.java <BR> - * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P> + * author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P> * * This version is equal to Brian Paul's version 1.2 1999/10/21 */ public class Gears implements GLEventListener { - static { - GLProfile.initSingleton(false); - } private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f; - private int gear1, gear2, gear3; + private int gear1=0, gear2=0, gear3=0; private float angle = 0.0f; + private int swapInterval; - private int prevMouseX, prevMouseY; private boolean mouseRButtonDown = false; + private int prevMouseX, prevMouseY; public static void main(String[] args) { // set argument 'NotFirstUIActionOnProcess' in the JNLP's application-desc tag for example @@ -37,9 +41,9 @@ public class Gears implements GLEventListener { // </application-desc> // boolean firstUIActionOnProcess = 0==args.length || !args[0].equals("NotFirstUIActionOnProcess") ; - Frame frame = new Frame("Gear Demo"); + java.awt.Frame frame = new java.awt.Frame("Gear Demo"); frame.setSize(300, 300); - frame.setLayout(new BorderLayout()); + frame.setLayout(new java.awt.BorderLayout()); final Animator animator = new Animator(); frame.addWindowListener(new java.awt.event.WindowAdapter() { @@ -64,12 +68,41 @@ public class Gears implements GLEventListener { final Gears gears = new Gears(); canvas.addGLEventListener(gears); - frame.add(canvas, BorderLayout.CENTER); + frame.add(canvas, java.awt.BorderLayout.CENTER); frame.validate(); frame.setVisible(true); animator.start(); } + + public Gears(int swapInterval) { + this.swapInterval = swapInterval; + } + + public Gears() { + this.swapInterval = 1; + } + + public void setGears(int g1, int g2, int g3) { + gear1 = g1; + gear2 = g2; + gear3 = g3; + } + + /** + * @return display list gear1 + */ + public int getGear1() { return gear1; } + + /** + * @return display list gear2 + */ + public int getGear2() { return gear2; } + + /** + * @return display list gear3 + */ + public int getGear3() { return gear3; } public void init(GLAutoDrawable drawable) { System.err.println("Gears: Init: "+drawable); @@ -84,12 +117,10 @@ public class Gears implements GLEventListener { System.err.println("GL_RENDERER: " + gl.glGetString(GL2.GL_RENDERER)); System.err.println("GL_VERSION: " + gl.glGetString(GL2.GL_VERSION)); - gl.setSwapInterval(1); - float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f }; - float red[] = { 0.8f, 0.1f, 0.0f, 1.0f }; - float green[] = { 0.0f, 0.8f, 0.2f, 1.0f }; - float blue[] = { 0.2f, 0.2f, 1.0f, 1.0f }; + float red[] = { 0.8f, 0.1f, 0.0f, 0.7f }; + float green[] = { 0.0f, 0.8f, 0.2f, 0.7f }; + float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f }; gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0); gl.glEnable(GL2.GL_CULL_FACE); @@ -98,42 +129,62 @@ public class Gears implements GLEventListener { gl.glEnable(GL2.GL_DEPTH_TEST); /* make the gears */ - gear1 = gl.glGenLists(1); - gl.glNewList(gear1, GL2.GL_COMPILE); - gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0); - gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); - gl.glEndList(); + if(0>=gear1) { + gear1 = gl.glGenLists(1); + gl.glNewList(gear1, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0); + gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f); + gl.glEndList(); + System.err.println("gear1 list created: "+gear1); + } else { + System.err.println("gear1 list reused: "+gear1); + } - gear2 = gl.glGenLists(1); - gl.glNewList(gear2, GL2.GL_COMPILE); - gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0); - gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); - gl.glEndList(); + if(0>=gear2) { + gear2 = gl.glGenLists(1); + gl.glNewList(gear2, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0); + gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f); + gl.glEndList(); + System.err.println("gear2 list created: "+gear2); + } else { + System.err.println("gear2 list reused: "+gear2); + } - gear3 = gl.glGenLists(1); - gl.glNewList(gear3, GL2.GL_COMPILE); - gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0); - gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); - gl.glEndList(); + if(0>=gear3) { + gear3 = gl.glGenLists(1); + gl.glNewList(gear3, GL2.GL_COMPILE); + gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0); + gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f); + gl.glEndList(); + System.err.println("gear3 list created: "+gear3); + } else { + System.err.println("gear3 list reused: "+gear3); + } gl.glEnable(GL2.GL_NORMALIZE); // MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); - MouseListener gearsMouse = new GearsMouseAdapter(); + MouseListener gearsMouse = new GearsMouseAdapter(); + KeyListener gearsKeys = new GearsKeyAdapter(); - if (drawable instanceof Component) { - Component comp = (Component) drawable; - new AWTMouseAdapter(gearsMouse).addTo(comp); - } else if (drawable instanceof Window) { + if (drawable instanceof Window) { Window window = (Window) drawable; window.addMouseListener(gearsMouse); + window.addKeyListener(gearsKeys); + } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) drawable; + new AWTMouseAdapter(gearsMouse).addTo(comp); + new AWTKeyAdapter(gearsKeys).addTo(comp); } } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - System.err.println("Gears: Reshape: "+x+"/"+y+" "+width+"x"+height); + System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height); GL2 gl = drawable.getGL().getGL2(); + gl.setSwapInterval(swapInterval); + float h = (float)height / (float)width; gl.glMatrixMode(GL2.GL_PROJECTION); @@ -147,6 +198,7 @@ public class Gears implements GLEventListener { public void dispose(GLAutoDrawable drawable) { System.err.println("Gears: Dispose"); + setGears(0, 0, 0); } public void display(GLAutoDrawable drawable) { @@ -156,11 +208,14 @@ public class Gears implements GLEventListener { // Get the GL corresponding to the drawable we are animating GL2 gl = drawable.getGL().getGL2(); + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + // Special handling for the case where the GLJPanel is translucent // and wants to be composited with other Java 2D content - if ((drawable instanceof GLJPanel) && - !((GLJPanel) drawable).isOpaque() && - ((GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) { + if (GLProfile.isAWTAvailable() && + (drawable instanceof javax.media.opengl.awt.GLJPanel) && + !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() && + ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) { gl.glClear(GL2.GL_DEPTH_BUFFER_BIT); } else { gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); @@ -315,6 +370,21 @@ public class Gears implements GLEventListener { gl.glEnd(); } + class GearsKeyAdapter extends KeyAdapter { + public void keyPressed(KeyEvent e) { + int kc = e.getKeyCode(); + if(KeyEvent.VK_LEFT == kc) { + view_roty -= 1; + } else if(KeyEvent.VK_RIGHT == kc) { + view_roty += 1; + } else if(KeyEvent.VK_UP == kc) { + view_rotx -= 1; + } else if(KeyEvent.VK_DOWN == kc) { + view_rotx += 1; + } + } + } + class GearsMouseAdapter extends MouseAdapter { public void mousePressed(MouseEvent e) { prevMouseX = e.getX(); @@ -339,8 +409,8 @@ public class Gears implements GLEventListener { Window window = (Window) source; width=window.getWidth(); height=window.getHeight(); - } else if (source instanceof Component) { - Component comp = (Component) source; + } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) { + java.awt.Component comp = (java.awt.Component) source; width=comp.getWidth(); height=comp.getHeight(); } else { diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java index 7afb354..e2af4b3 100644 --- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java +++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java @@ -240,8 +240,8 @@ public class HWShadowmapsSimple extends Demo { decal = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/decal_image.png"), true, TextureIO.PNG); - decal.setTexParameteri(GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT); - decal.setTexParameteri(GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT); + decal.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT); + decal.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT); light_image = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/nvlogo_spot.png"), true, TextureIO.PNG); @@ -573,10 +573,10 @@ public class HWShadowmapsSimple extends Demo { gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glDisable(GL2.GL_LIGHTING); - decal.bind(); - decal.enable(); + decal.bind(gl); + decal.enable(gl); gl.glCallList(quad); - decal.disable(); + decal.disable(gl); gl.glEnable(GL2.GL_LIGHTING); texgen(gl, false); @@ -647,8 +647,8 @@ public class HWShadowmapsSimple extends Demo { applyTransform(gl, spotlightInverseTransform); gl.glMatrixMode(GL2.GL_MODELVIEW); - light_image.bind(); - light_image.enable(); + light_image.bind(gl); + light_image.enable(gl); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); gl.glActiveTexture(GL2.GL_TEXTURE0); @@ -660,7 +660,7 @@ public class HWShadowmapsSimple extends Demo { render_scene(gl, cameraTransform, drawable, params); gl.glActiveTexture(GL2.GL_TEXTURE1); - light_image.disable(); + light_image.disable(gl); gl.glActiveTexture(GL2.GL_TEXTURE0); render_manipulators(gl, cameraTransform, drawable, params); @@ -694,8 +694,8 @@ public class HWShadowmapsSimple extends Demo { applyTransform(gl, spotlightInverseTransform); gl.glMatrixMode(GL2.GL_MODELVIEW); - light_image.bind(); - light_image.enable(); + light_image.bind(gl); + light_image.enable(gl); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); // depth compare @@ -729,7 +729,7 @@ public class HWShadowmapsSimple extends Demo { render_scene(gl, cameraTransform, drawable, params); gl.glActiveTexture(GL2.GL_TEXTURE1); - light_image.disable(); + light_image.disable(gl); gl.glActiveTexture(GL2.GL_TEXTURE2); gl.glDisable(GL2.GL_TEXTURE_2D); gl.glActiveTexture(GL2.GL_TEXTURE0); @@ -769,8 +769,8 @@ public class HWShadowmapsSimple extends Demo { glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); gl.glMatrixMode(GL2.GL_MODELVIEW); - light_image.bind(); - light_image.enable(); + light_image.bind(gl); + light_image.enable(gl); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); gl.glActiveTexture(GL2.GL_TEXTURE0); @@ -785,7 +785,7 @@ public class HWShadowmapsSimple extends Demo { render_scene(gl, spotlightTransform, null, null); gl.glActiveTexture(GL2.GL_TEXTURE1); - light_image.disable(); + light_image.disable(gl); gl.glActiveTexture(GL2.GL_TEXTURE0); } diff --git a/src/demos/j2d/CustomText.java b/src/demos/j2d/CustomText.java index 5918dc9..3a68761 100755 --- a/src/demos/j2d/CustomText.java +++ b/src/demos/j2d/CustomText.java @@ -210,11 +210,11 @@ public class CustomText extends Demo { g.fillRect(1, 1, 1, 1); g.dispose(); backgroundTexture = AWTTextureIO.newTexture(gl.getGLProfile(), bgImage, false); - backgroundTexture.bind(); - backgroundTexture.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); - backgroundTexture.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - backgroundTexture.setTexParameteri(GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); - backgroundTexture.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); + backgroundTexture.bind(gl); + backgroundTexture.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + backgroundTexture.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + backgroundTexture.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); + backgroundTexture.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); // Create the text renderer renderer = new TextRenderer(new Font("Serif", Font.PLAIN, 72), true, true, @@ -299,8 +299,8 @@ public class CustomText extends Demo { gl.glLoadIdentity(); // Draw the background texture - backgroundTexture.enable(); - backgroundTexture.bind(); + backgroundTexture.enable(gl); + backgroundTexture.bind(gl); TextureCoords coords = backgroundTexture.getImageTexCoords(); int w = drawable.getWidth(); int h = drawable.getHeight(); @@ -317,7 +317,7 @@ public class CustomText extends Demo { gl.glTexCoord2f(fw * coords.left(), fh * coords.top()); gl.glVertex3f(0, h, 0); gl.glEnd(); - backgroundTexture.disable(); + backgroundTexture.disable(gl); // Render all text renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); diff --git a/src/demos/j2d/FlyingText.java b/src/demos/j2d/FlyingText.java index 929803e..debb9c7 100755 --- a/src/demos/j2d/FlyingText.java +++ b/src/demos/j2d/FlyingText.java @@ -249,11 +249,11 @@ public class FlyingText extends Demo { g.fillRect(1, 1, 1, 1); g.dispose(); backgroundTexture = AWTTextureIO.newTexture(gl.getGLProfile(), bgImage, false); - backgroundTexture.bind(); - backgroundTexture.setTexParameteri(GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); - backgroundTexture.setTexParameteri(GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); - backgroundTexture.setTexParameteri(GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT); - backgroundTexture.setTexParameteri(GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT); + backgroundTexture.bind(gl); + backgroundTexture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); + backgroundTexture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); + backgroundTexture.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT); + backgroundTexture.setTexParameteri(gl, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT); // Create the text renderer renderer = new TextRenderer(new Font("Serif", Font.PLAIN, 72), true, true); @@ -353,8 +353,8 @@ public class FlyingText extends Demo { gl.glLoadIdentity(); // Draw the background texture - backgroundTexture.enable(); - backgroundTexture.bind(); + backgroundTexture.enable(gl); + backgroundTexture.bind(gl); TextureCoords coords = backgroundTexture.getImageTexCoords(); int w = drawable.getWidth(); int h = drawable.getHeight(); @@ -371,7 +371,7 @@ public class FlyingText extends Demo { gl.glTexCoord2f(fw * coords.left(), fh * coords.top()); gl.glVertex3f(0, h, 0); gl.glEnd(); - backgroundTexture.disable(); + backgroundTexture.disable(gl); // Render all text renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); diff --git a/src/demos/misc/TiledRendering.java b/src/demos/misc/TiledRendering.java index e814610..86de0bb 100755 --- a/src/demos/misc/TiledRendering.java +++ b/src/demos/misc/TiledRendering.java @@ -1,6 +1,6 @@ package demos.misc; -import com.jogamp.opengl.util.FileUtil; +import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.TGAWriter; import com.jogamp.opengl.util.awt.ImageUtil; import com.jogamp.opengl.util.gl2.TileRenderer; @@ -106,7 +106,7 @@ public class TiledRendering { tga.close(); } else { ImageUtil.flipImageVertically(img); - if (!ImageIO.write(img, FileUtil.getFileSuffix(file), file)) { + if (!ImageIO.write(img, IOUtil.getFileSuffix(file), file)) { System.err.println("Error writing file using ImageIO (unsupported file format?)"); } } diff --git a/src/demos/particles/engine/Engine.java b/src/demos/particles/engine/Engine.java index d769457..d443ac2 100755 --- a/src/demos/particles/engine/Engine.java +++ b/src/demos/particles/engine/Engine.java @@ -37,6 +37,7 @@ package demos.particles.engine; import javax.media.opengl.*; + import com.jogamp.opengl.util.texture.*; import java.net.*; import java.util.*; @@ -78,12 +79,12 @@ public class Engine { } } - public void init() { + public void init(GL gl) { try { ClassLoader c1 = this.getClass().getClassLoader(); URL url = c1.getResource(path); texture = TextureIO.newTexture(url, false, null); - texture.enable(); + texture.enable(gl); } catch(IOException e) { e.printStackTrace(); diff --git a/src/demos/particles/engine/GLComponent.java b/src/demos/particles/engine/GLComponent.java index 7194861..46a0940 100755 --- a/src/demos/particles/engine/GLComponent.java +++ b/src/demos/particles/engine/GLComponent.java @@ -106,7 +106,7 @@ public class GLComponent extends GLCanvas implements GLEventListener { animator.start(); - engine.init(); + engine.init(gl); } diff --git a/src/demos/particles/engine/Particle.java b/src/demos/particles/engine/Particle.java index d9858dd..81fbe25 100755 --- a/src/demos/particles/engine/Particle.java +++ b/src/demos/particles/engine/Particle.java @@ -58,7 +58,7 @@ public class Particle { public void draw(GL2 gl, Texture texture, RGBA tendToColor) { adjust(tendToColor); - texture.bind(); + texture.bind(gl); gl.glColor4f(rgba.r,rgba.g,rgba.b,rgba.a); gl.glBegin(GL2.GL_QUADS); diff --git a/src/demos/proceduralTexturePhysics/Water.java b/src/demos/proceduralTexturePhysics/Water.java index 3e4fad4..d62379b 100644 --- a/src/demos/proceduralTexturePhysics/Water.java +++ b/src/demos/proceduralTexturePhysics/Water.java @@ -33,7 +33,7 @@ package demos.proceduralTexturePhysics; -import com.jogamp.opengl.util.FileUtil; +import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; @@ -272,11 +272,11 @@ public class Water { // Draw quad over full display gl.glActiveTexture(GL2.GL_TEXTURE0); - dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(); - dynamicTextures[CA_TEXTURE_NORMAL_MAP].disable(); + dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl); + dynamicTextures[CA_TEXTURE_NORMAL_MAP].disable(gl); gl.glActiveTexture(GL2.GL_TEXTURE3); - cubemap.bind(); - cubemap.enable(); + cubemap.bind(gl); + cubemap.enable(gl); gl.glColor4f(1, 1, 1, 1); gl.glBegin(GL2.GL_QUADS); @@ -307,7 +307,7 @@ public class Water { gl.glEnd(); - cubemap.disable(); + cubemap.disable(gl); gl.glDisable(GL2.GL_FRAGMENT_PROGRAM_ARB); break; @@ -316,7 +316,7 @@ public class Water { case CA_FULLSCREEN_NORMALMAP: { // Draw quad over full display gl.glActiveTexture(GL2.GL_TEXTURE0); - dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(); + dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl); gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]); break; @@ -334,7 +334,7 @@ public class Water { case CA_FULLSCREEN_FORCE: { // Draw quad over full display gl.glActiveTexture(GL2.GL_TEXTURE0); - dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(); + dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl); gl.glCallList(displayListIDs[CA_DRAW_SCREEN_QUAD]); break; @@ -344,7 +344,7 @@ public class Water { // Draw quad over full display // lower left gl.glActiveTexture(GL2.GL_TEXTURE0); - dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(); + dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); @@ -363,7 +363,7 @@ public class Water { gl.glPopMatrix(); // upper left - dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(); + dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); @@ -498,7 +498,7 @@ public class Water { initialMapData = TextureIO.newTextureData(glp, getClass().getClassLoader().getResourceAsStream(initialMapFilename), false, - FileUtil.getFileSuffix(initialMapFilename)); + IOUtil.getFileSuffix(initialMapFilename)); } catch (IOException e) { throw new GLException(e); } @@ -694,11 +694,11 @@ public class Water { switch (flipState) { case 0: - texHeightInput = dynamicTextures[CA_TEXTURE_HEIGHT_SOURCE].getTextureObject(); // initial height map. - texHeightOutput = dynamicTextures[CA_TEXTURE_HEIGHT_TARGET].getTextureObject(); // next height map. + texHeightInput = dynamicTextures[CA_TEXTURE_HEIGHT_SOURCE].getTextureObject(gl); // initial height map. + texHeightOutput = dynamicTextures[CA_TEXTURE_HEIGHT_TARGET].getTextureObject(gl); // next height map. - texVelocityInput = dynamicTextures[CA_TEXTURE_VELOCITY_SOURCE].getTextureObject(); // initial velocity. - texVelocityOutput = dynamicTextures[CA_TEXTURE_VELOCITY_TARGET].getTextureObject(); // next velocity. + texVelocityInput = dynamicTextures[CA_TEXTURE_VELOCITY_SOURCE].getTextureObject(gl); // initial velocity. + texVelocityOutput = dynamicTextures[CA_TEXTURE_VELOCITY_TARGET].getTextureObject(gl); // next velocity. // Clear initial velocity texture to 0x80 == gray gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); @@ -776,7 +776,7 @@ public class Water { // Now we need to copy the resulting pixels into the intermediate force field texture gl.glActiveTexture(GL2.GL_TEXTURE2); - dynamicTextures[CA_TEXTURE_FORCE_INTERMEDIATE].bind(); + dynamicTextures[CA_TEXTURE_FORCE_INTERMEDIATE].bind(gl); // use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]); @@ -818,7 +818,7 @@ public class Water { // Now we need to copy the resulting pixels into the intermediate force field texture gl.glActiveTexture(GL2.GL_TEXTURE1); - dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(); + dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl); // use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]); @@ -837,7 +837,7 @@ public class Water { gl.glActiveTexture(GL2.GL_TEXTURE0); gl.glBindTexture(GL2.GL_TEXTURE_2D, texVelocityInput); gl.glActiveTexture(GL2.GL_TEXTURE1); - dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(); + dynamicTextures[CA_TEXTURE_FORCE_TARGET].bind(gl); gl.glActiveTexture(GL2.GL_TEXTURE2); gl.glDisable(GL2.GL_TEXTURE_2D); gl.glActiveTexture(GL2.GL_TEXTURE3); @@ -985,7 +985,7 @@ public class Water { // Now we need to copy the resulting pixels into the normal map gl.glActiveTexture(GL2.GL_TEXTURE0); - dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(); + dynamicTextures[CA_TEXTURE_NORMAL_MAP].bind(gl); // use CopyTexSubImage for speed (even though we copy all of it) since we pre-allocated the texture gl.glCopyTexSubImage2D(GL2.GL_TEXTURE_2D, 0, 0, 0, 0, 0, initialMapDimensions[0], initialMapDimensions[1]); @@ -994,8 +994,8 @@ public class Water { private void drawInteriorBoundaryObjects(GL2 gl) { gl.glActiveTexture(GL2.GL_TEXTURE0); - initialMapTex.bind(); - initialMapTex.enable(); + initialMapTex.bind(gl); + initialMapTex.enable(gl); gl.glEnable(GL2.GL_ALPHA_TEST); @@ -1012,7 +1012,7 @@ public class Water { if (spinLogo) { gl.glActiveTexture(GL2.GL_TEXTURE0); - spinTex.bind(); + spinTex.bind(gl); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); gl.glRotatef(angle, 0, 0, 1); @@ -1038,15 +1038,15 @@ public class Water { initialMapTex = TextureIO.newTexture(initialMapData); spinTex = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream(spinFilename), false, - FileUtil.getFileSuffix(spinFilename)); + IOUtil.getFileSuffix(spinFilename)); dropletTex = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream(dropletFilename), false, - FileUtil.getFileSuffix(dropletFilename)); + IOUtil.getFileSuffix(dropletFilename)); // load the cubemap texture - cubemap = Cubemap.loadFromStreams(getClass().getClassLoader(), + cubemap = Cubemap.loadFromStreams(gl, + getClass().getClassLoader(), cubeMapFilenamePrefix, - cubeMapFilenameSuffix, - true); + cubeMapFilenameSuffix, true); // now create dummy intermediate textures from the initial map texture for (int i = 0; i < CA_NUM_DYNAMIC_TEXTURES; i++) { @@ -1055,11 +1055,11 @@ public class Water { initialMapData = null; - texHeightInput = initialMapTex.getTextureObject(); // initial height map. - texHeightOutput = dynamicTextures[CA_TEXTURE_HEIGHT_TARGET].getTextureObject(); // next height map. + texHeightInput = initialMapTex.getTextureObject(gl); // initial height map. + texHeightOutput = dynamicTextures[CA_TEXTURE_HEIGHT_TARGET].getTextureObject(gl); // next height map. - texVelocityInput = dynamicTextures[CA_TEXTURE_VELOCITY_SOURCE].getTextureObject(); // initial velocity. - texVelocityOutput = dynamicTextures[CA_TEXTURE_VELOCITY_TARGET].getTextureObject(); // next velocity. + texVelocityInput = dynamicTextures[CA_TEXTURE_VELOCITY_SOURCE].getTextureObject(gl); // initial velocity. + texVelocityOutput = dynamicTextures[CA_TEXTURE_VELOCITY_TARGET].getTextureObject(gl); // next velocity. } private void createAndWriteUVOffsets(GL2 gl, int width, int height) { @@ -1154,8 +1154,8 @@ public class Water { gl.glDisable(GL2.GL_VERTEX_PROGRAM_ARB); gl.glActiveTexture(GL2.GL_TEXTURE0); - dropletTex.bind(); - dropletTex.enable(); + dropletTex.bind(gl); + dropletTex.enable(gl); gl.glActiveTexture(GL2.GL_TEXTURE1); gl.glDisable(GL2.GL_TEXTURE_2D); diff --git a/src/demos/readbuffer/Main.java b/src/demos/readbuffer/Main.java index 426bdd7..d0ce55b 100755 --- a/src/demos/readbuffer/Main.java +++ b/src/demos/readbuffer/Main.java @@ -68,7 +68,7 @@ public class Main implements WindowListener, MouseListener, SurfaceUpdatedListen Window nWindow = NewtFactory.createWindow(nScreen, capsOffscreen); GLWindow windowOffscreen = GLWindow.create(nWindow); - windowOffscreen.enablePerfLog(true); + windowOffscreen.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); windowOffscreen.setSize(w, h); windowOffscreen.setVisible(true); return windowOffscreen; @@ -139,11 +139,11 @@ public class Main implements WindowListener, MouseListener, SurfaceUpdatedListen // System.out.println("..............................."); windowOffscreen.display(); if ( TEST_READBUFFER2SCREEN == typeTest ) { - if ( windowOffscreen.getDuration() >= 10000) { + if ( windowOffscreen.getTotalFPSDuration() >= 10000) { break; } } else { - if ( windowOffscreen.getTotalFrames() >= 10) { + if ( windowOffscreen.getTotalFPSFrames() >= 10) { break; } } diff --git a/src/demos/readbuffer/ReadBuffer2Screen.java b/src/demos/readbuffer/ReadBuffer2Screen.java index 13e6508..fd7f5b5 100755 --- a/src/demos/readbuffer/ReadBuffer2Screen.java +++ b/src/demos/readbuffer/ReadBuffer2Screen.java @@ -64,12 +64,12 @@ public class ReadBuffer2Screen extends ReadBufferBase { float f_edge = 1f; if(null==readTextureVertices) { - //readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex", + //readTextureVertices = GLArrayDataClient.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, // 2, GL.GL_FLOAT, true, 4); - readTextureVertices = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_VERTEX_ARRAY, "mgl_Vertex", + readTextureVertices = GLArrayDataServer.createFixed(GLPointerFunc.GL_VERTEX_ARRAY, 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); readTextureVertices.setEnableAlways(enableBufferAlways); - readTextureVertices.setVBOUsage(enableBufferVBO); + readTextureVertices.setVBOEnabled(enableBufferVBO); { FloatBuffer vb = (FloatBuffer)readTextureVertices.getBuffer(); vb.put(-f_edge); vb.put(-f_edge); @@ -130,8 +130,8 @@ public class ReadBuffer2Screen extends ReadBufferBase { if(!readBufferUtil.isValid()) return; // Now draw one quad with the texture - readBufferUtil.getTexture().enable(); - readBufferUtil.getTexture().bind(); + readBufferUtil.getTexture().enable(gl); + readBufferUtil.getTexture().bind(gl); if(gl.isGL2ES1()) { // gl.getGL2ES1().glTexEnvi(GL2ES1.GL_TEXTURE_ENV, GL2ES1.GL_TEXTURE_ENV_MODE, GL2ES1.GL_REPLACE); @@ -144,22 +144,22 @@ public class ReadBuffer2Screen extends ReadBufferBase { if(null!=readTextureCoords) { readTextureCoords.enableBuffer(gl, true); } - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, readTextureVertices.getElementNumber()); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, readTextureVertices.getElementCount()); /** if(null!=readTextureCoords) { readTextureCoords.enableBuffer(gl, false); } readTextureVertices.enableBuffer(gl, false); */ - readBufferUtil.getTexture().disable(); + readBufferUtil.getTexture().disable(gl); } void updateTextureCoords(GL gl, boolean force) { if(force || null==readTextureCoords) { - readTextureCoords = GLArrayDataServer.createFixed(gl, GLPointerFunc.GL_TEXTURE_COORD_ARRAY, "mgl_MultiTexCoord0", + readTextureCoords = GLArrayDataServer.createFixed(GLPointerFunc.GL_TEXTURE_COORD_ARRAY, 2, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); readTextureCoords.setEnableAlways(enableBufferAlways); - readTextureCoords.setVBOUsage(enableBufferVBO); + readTextureCoords.setVBOEnabled(enableBufferVBO); { TextureCoords coords = readBufferUtil.getTexture().getImageTexCoords(); FloatBuffer cb = (FloatBuffer)readTextureCoords.getBuffer(); diff --git a/src/demos/readbuffer/ReadBufferBase.java b/src/demos/readbuffer/ReadBufferBase.java index 6922f02..d392d1c 100755 --- a/src/demos/readbuffer/ReadBufferBase.java +++ b/src/demos/readbuffer/ReadBufferBase.java @@ -80,7 +80,7 @@ public class ReadBufferBase implements GLEventListener { } public void dispose(GLAutoDrawable drawable) { - readBufferUtil.dispose(); + readBufferUtil.dispose(drawable.getGL()); } public void display(GLAutoDrawable drawable) { diff --git a/src/demos/readbuffer/ReadBufferUtil.java b/src/demos/readbuffer/ReadBufferUtil.java index 85680c7..e271767 100755 --- a/src/demos/readbuffer/ReadBufferUtil.java +++ b/src/demos/readbuffer/ReadBufferUtil.java @@ -88,9 +88,9 @@ public class ReadBufferUtil { gl.glReadPixels(0, 0, drawable.getWidth(), drawable.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, readPixelBuffer); readPixelBuffer.rewind(); if(newData) { - readTexture.updateImage(readTextureData); + readTexture.updateImage(gl, readTextureData); } else { - readTexture.updateSubImage(readTextureData, 0, + readTexture.updateSubImage(gl, readTextureData, 0, 0, 0, // src offset 0, 0, // dst offset drawable.getWidth(), drawable.getHeight()); @@ -99,8 +99,8 @@ public class ReadBufferUtil { } } - public void dispose() { - readTexture.dispose(); + public void dispose(GL gl) { + readTexture.destroy(gl); readTextureData = null; readPixelBuffer.clear(); readPixelBuffer = null; diff --git a/src/demos/readbuffer/Surface2File.java b/src/demos/readbuffer/Surface2File.java index 2303a1c..051094c 100755 --- a/src/demos/readbuffer/Surface2File.java +++ b/src/demos/readbuffer/Surface2File.java @@ -47,8 +47,8 @@ public class Surface2File implements SurfaceUpdatedListener { ReadBufferUtil readBufferUtil = new ReadBufferUtil(); int shotNum=0; - public void dispose() { - readBufferUtil.dispose(); + public void dispose(GL gl) { + readBufferUtil.dispose(gl); } public void surfaceUpdated(Object updater, NativeSurface surface, long when) { diff --git a/src/demos/tennis/Tennis.java b/src/demos/tennis/Tennis.java new file mode 100644 index 0000000..2460f90 --- /dev/null +++ b/src/demos/tennis/Tennis.java @@ -0,0 +1,920 @@ +package demos.tennis;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.texture.Texture;
+import com.jogamp.opengl.util.texture.TextureCoords;
+import com.jogamp.opengl.util.texture.TextureIO;
+
+import javax.media.opengl.GL;
+//import javax.media.opengl.glu.GLU;
+import javax.swing.JOptionPane;
+
+//import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+//import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import com.jogamp.newt.Window;
+//import com.jogamp.newt.event.InputEvent;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.MouseAdapter;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.awt.AWTKeyAdapter;
+import com.jogamp.newt.event.awt.AWTMouseAdapter;
+
+import java.awt.AWTException;
+import java.awt.Cursor;
+import java.awt.Image;
+import java.awt.MouseInfo;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+//import java.io.ByteArrayOutputStream;
+//import java.io.IOException;
+//import java.io.PrintStream;
+
+/**
+ * Tennis.java <BR>
+ * author: Fofonov Alexey <P>
+ */
+
+public class Tennis implements GLEventListener {
+ static {
+ GLProfile.initSingleton();
+ }
+ private float view_rotx = 0.0f, view_roty = 0.0f, view_rotz = 0.0f; //View angles
+ private float sx = 0.0f, sy = 0.0f; //X, Y coords of Mydesk
+ private float spx,spy,spz; //Speed of the ball
+ private float BallCx = 0.0f, BallCy = 0.0f, BallCz = 0.0f; //Coords of the ball
+ private float EnDeskCx = 0.0f, EnDeskCy = 0.0f; //X, Y coords of Endesk
+ private int cube=0, mydesk=0, endesk=0, ball=0, box=0; //Flags of the existence
+ private int swapInterval;
+ private static Texture[] texture;
+ private float Bax=0, Bay=0; //Acceleration summands
+ private float Vec=3; //Balls direction
+ private boolean CanF=false; //Ready for play
+
+ private int WindowW=0, WindowH=0;
+
+ private float LPositionDX=0, NPositionDX=0; //Mouse positions
+ private float LPositionDY=0, NPositionDY=0; //
+ private float DspeedX=0, DspeedY=0; //Speed of Mydesk
+
+ private boolean mouseButtonDown = false, control = true;
+ private int prevMouseX, prevMouseY;
+
+ public static void main(String[] args) {
+ // set argument 'NotFirstUIActionOnProcess' in the JNLP's application-desc tag for example
+ // <application-desc main-class="demos.j2d.TextCube"/>
+ // <argument>NotFirstUIActionOnProcess</argument>
+ // </application-desc>
+ // boolean firstUIActionOnProcess = 0==args.length || !args[0].equals("NotFirstUIActionOnProcess") ;
+
+ java.awt.Frame frame = new java.awt.Frame("Tennis Demo");
+ frame.setSize(640, 480);
+ frame.setLayout(new java.awt.BorderLayout());
+
+ final Animator animator = new Animator();
+ frame.addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(java.awt.event.WindowEvent e) {
+ // Run this on another thread than the AWT event queue to
+ // make sure the call to Animator.stop() completes before
+ // exiting
+ new Thread(new Runnable() {
+ public void run() {
+ animator.stop();
+ System.exit(0);
+ }
+ }).start();
+ }
+ });
+
+ GLCanvas canvas = new GLCanvas();
+ animator.add(canvas);
+ // GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ // GLCanvas canvas = new GLCanvas(caps);
+
+ final Tennis tennis = new Tennis();
+ canvas.addGLEventListener(tennis);
+
+ frame.add(canvas, java.awt.BorderLayout.CENTER);
+ frame.validate();
+
+ //Hide the mouse cursor
+ Toolkit t = Toolkit.getDefaultToolkit();
+ Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+ Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none");
+ frame.setCursor(noCursor);
+
+ frame.setVisible(true);
+ animator.start();
+ }
+
+ public Tennis(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public Tennis() {
+ this.swapInterval = 1;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ System.err.println("Tennis: Init: "+drawable);
+ // Use debug pipeline
+ // drawable.setGL(new DebugGL(drawable.getGL()));
+
+ GL2 gl = drawable.getGL().getGL2();
+
+ System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
+ System.err.println("INIT GL IS: " + gl.getClass().getName());
+ System.err.println("GL_VENDOR: " + gl.glGetString(GL2.GL_VENDOR));
+ System.err.println("GL_RENDERER: " + gl.glGetString(GL2.GL_RENDERER));
+ System.err.println("GL_VERSION: " + gl.glGetString(GL2.GL_VERSION));
+
+ float mat_specular[] =
+ { 1.0f, 1.0f, 1.0f, 1.0f };
+ float mat_shininess[] =
+ { 25.0f };
+ float light_position[] =
+ { 1.0f, 1.0f, 1.0f, 0.0f };
+
+ float red[] = { 0.8f, 0.1f, 0.0f, 0.7f };
+ float yellow[] = { 0.8f, 0.75f, 0.0f, 0.7f };
+ float blue[] = { 0.2f, 0.2f, 1.0f, 0.7f };
+ float brown[] = { 0.8f, 0.4f, 0.1f, 0.7f };
+
+ texture = new Texture[5];
+
+ //Load textures
+ try {
+ System.err.println("Loading texture...");
+ texture[0] = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/TennisTop.png"),
+ false,
+ TextureIO.PNG);
+ texture[1] = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/TennisBottom.png"),
+ false,
+ TextureIO.PNG);
+ texture[2] = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/TennisMyDesk.png"),
+ false,
+ TextureIO.PNG);
+ texture[3] = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/TennisEnDesk.png"),
+ false,
+ TextureIO.PNG);
+ texture[4] = TextureIO.newTexture(getClass().getClassLoader().getResourceAsStream("demos/data/images/Stars.png"),
+ false,
+ TextureIO.PNG);
+ System.err.println("Texture0 estimated memory size = " + texture[0].getEstimatedMemorySize());
+ System.err.println("Texture1 estimated memory size = " + texture[1].getEstimatedMemorySize());
+ System.err.println("Texture2 estimated memory size = " + texture[2].getEstimatedMemorySize());
+ System.err.println("Texture3 estimated memory size = " + texture[3].getEstimatedMemorySize());
+ System.err.println("Stars estimated memory size = " + texture[4].getEstimatedMemorySize());
+ } catch (IOException e) {
+ e.printStackTrace();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(bos));
+ JOptionPane.showMessageDialog(null,
+ bos.toString(),
+ "Error loading texture",
+ JOptionPane.ERROR_MESSAGE);
+ throw new GLException(e);
+ //return;
+ }
+
+ gl.glShadeModel(GL2.GL_SMOOTH); // Enable Smooth Shading
+ gl.glClearDepth(1.0f); // Depth Buffer Setup
+ gl.glEnable(GL2.GL_DEPTH_TEST); // Enables Depth Testing
+ gl.glDepthFunc(GL2.GL_LEQUAL); // The Type Of Depth Testing To Do
+
+ // Really Nice Perspective Calculations
+ gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
+ gl.glEnable(GL2.GL_TEXTURE_2D);
+
+ // Texture filter
+ gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NONE);
+ gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NONE);
+
+ // Light and material
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, mat_specular, 0);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SHININESS, mat_shininess, 0);
+ gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_position, 0);
+ gl.glEnable(GL2.GL_LIGHTING);
+ gl.glEnable(GL2.GL_LIGHT0);
+
+
+ /* make the objects */
+ if(0>=cube) {
+ cube = gl.glGenLists(1);
+ gl.glNewList(cube, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, brown, 0);
+ cube(gl);
+ gl.glEndList();
+ System.err.println("cube list created: "+cube);
+ } else {
+ System.err.println("cube list reused: "+cube);
+ }
+
+ if(0>=box) {
+ box = gl.glGenLists(1);
+ gl.glNewList(box, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, brown, 0);
+ box(gl);
+ gl.glEndList();
+ System.err.println("box list created: "+box);
+ } else {
+ System.err.println("box list reused: "+box);
+ }
+
+ if(0>=mydesk) {
+ mydesk = gl.glGenLists(1);
+ gl.glNewList(mydesk, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0);
+ desk(gl, 2);
+ gl.glEndList();
+ System.err.println("mydesk list created: "+mydesk);
+ } else {
+ System.err.println("mydesk list reused: "+mydesk);
+ }
+
+ if(0>=endesk) {
+ endesk = gl.glGenLists(1);
+ gl.glNewList(endesk, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0);
+ desk(gl, 3);
+ gl.glEndList();
+ System.err.println("endesk list created: "+endesk);
+ } else {
+ System.err.println("endesk list reused: "+endesk);
+ }
+
+ if(0>=ball) {
+ ball = gl.glGenLists(1);
+ gl.glNewList(ball, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, yellow, 0);
+ ball(gl);
+ gl.glEndList();
+ System.err.println("ball list created: "+ball);
+ } else {
+ System.err.println("ball list reused: "+ball);
+ }
+
+ gl.glEnable(GL2.GL_NORMALIZE);
+
+ MouseListener tennisMouse = new TennisMouseAdapter();
+ KeyListener tennisKeys = new TennisKeyAdapter();
+
+ if (drawable instanceof Window) {
+ Window window = (Window) drawable;
+ window.addMouseListener(tennisMouse);
+ window.addKeyListener(tennisKeys);
+ } else if (GLProfile.isAWTAvailable() && drawable instanceof java.awt.Component) {
+ java.awt.Component comp = (java.awt.Component) drawable;
+ new AWTMouseAdapter(tennisMouse).addTo(comp);
+ new AWTKeyAdapter(tennisKeys).addTo(comp);
+ }
+ }
+
+ public void dispose(GLAutoDrawable drawable) {
+ System.err.println("Tennis: Dispose");
+ }
+
+ public void display(GLAutoDrawable drawable) {
+
+ // Get the GL corresponding to the drawable we are animating
+ GL2 gl = drawable.getGL().getGL2();
+
+ if (mouseButtonDown == false && control == true)
+ MovMydesk();
+ MoveSphere();
+ MoveEnDesk();
+
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+
+ // Special handling for the case where the GLJPanel is translucent
+ // and wants to be composited with other Java 2D content
+ if (GLProfile.isAWTAvailable() &&
+ (drawable instanceof javax.media.opengl.awt.GLJPanel) &&
+ !((javax.media.opengl.awt.GLJPanel) drawable).isOpaque() &&
+ ((javax.media.opengl.awt.GLJPanel) drawable).shouldPreserveColorBufferIfTranslucent()) {
+ gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
+ } else {
+ gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ }
+
+ // Place the box and call its display list
+ gl.glDisable(GL2.GL_DEPTH_TEST);
+ gl.glCallList(box);
+ gl.glEnable(GL2.GL_DEPTH_TEST);
+
+ // Rotate the entire assembly of tennis based on how the user
+ // dragged the mouse around
+ gl.glPushMatrix();
+ gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
+ gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
+ gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
+
+ // Place the cube and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(0.0f, 0.0f, 0.0f);
+ gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(cube);
+ gl.glPopMatrix();
+
+ // Place the mydesk and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(sx, sy, 3.0f);
+ gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(mydesk);
+ gl.glPopMatrix();
+
+ // Place the endesk and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(EnDeskCx, EnDeskCy, -3.0f);
+ gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(endesk);
+ gl.glPopMatrix();
+
+ // Place the ball and call its display list
+ gl.glPushMatrix();
+ gl.glTranslatef(BallCx, BallCy, BallCz);
+ gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f);
+ gl.glCallList(ball);
+ gl.glPopMatrix();
+
+ // Remember that every push needs a pop; this one is paired with
+ // rotating the entire tennis assembly
+ gl.glPopMatrix();
+ }
+
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ {
+
+ System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height);
+ GL2 gl = drawable.getGL().getGL2();
+
+ gl.setSwapInterval(swapInterval);
+
+ float h = (float)height / (float)width;
+
+ WindowW = width;
+ WindowH = height;
+
+ gl.glMatrixMode(GL2.GL_PROJECTION);
+
+ gl.glLoadIdentity();
+
+ if (h<1)
+ gl.glFrustum(-1.0f, 1.0f, -h, h, 1.0f, 60.0f);
+ else
+ {
+ h = 1.0f/h;
+ gl.glFrustum(-h, h, -1.0f, 1.0f, 1.0f, 60.0f);
+ }
+
+ gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0.0f, 0.0f, -6.0f);
+
+ }
+
+ public static void cube(GL2 gl)
+ {
+
+ gl.glShadeModel(GL2.GL_FLAT);
+
+ /* draw left sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(1.0f, 0.0f, 0.0f);
+ gl.glVertex3f(-2.0f, -1.5f, -3.0f);
+ gl.glVertex3f(-2.0f, 1.5f, -3.0f);
+ gl.glVertex3f(-2.0f, 1.5f, 3.0f);
+ gl.glVertex3f(-2.0f, -1.5f, 3.0f);
+
+ gl.glNormal3f(-1.0f, 0.0f, 0.0f);
+ gl.glVertex3f(-2.05f, -1.55f, -3.0f);
+ gl.glVertex3f(-2.05f, 1.55f, -3.0f);
+ gl.glVertex3f(-2.05f, 1.55f, 3.0f);
+ gl.glVertex3f(-2.05f, -1.55f, 3.0f);
+
+ gl.glEnd();
+
+ if (texture[0] != null) {
+ texture[0].enable(gl);
+ texture[0].bind(gl);
+ gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+ TextureCoords coords = texture[0].getImageTexCoords();
+
+ /* draw up sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(0.0f, -1.0f, 0.0f);
+ gl.glTexCoord2f(coords.left(), coords.top());
+ gl.glVertex3f(-2.0f, 1.5f, -3.0f);
+ gl.glTexCoord2f(coords.left(), coords.bottom());
+ gl.glVertex3f(-2.0f, 1.5f, 3.0f);
+ gl.glTexCoord2f(coords.right(), coords.bottom());
+ gl.glVertex3f( 2.0f, 1.5f, 3.0f);
+ gl.glTexCoord2f(coords.right(), coords.top());
+ gl.glVertex3f( 2.0f, 1.5f, -3.0f);
+
+ gl.glEnd();
+
+ texture[0].disable(gl);
+ }
+
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(0.0f, 1.0f, 0.0f);
+ gl.glVertex3f(-2.05f, 1.55f, -3.0f);
+ gl.glVertex3f(-2.05f, 1.55f, 3.0f);
+ gl.glVertex3f( 2.05f, 1.55f, 3.0f);
+ gl.glVertex3f( 2.05f, 1.55f, -3.0f);
+
+ gl.glEnd();
+
+ /* draw right sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(-1.0f, 0.0f, 0.0f);
+ gl.glVertex3f(2.0f, -1.5f, -3.0f);
+ gl.glVertex3f(2.0f, 1.5f, -3.0f);
+ gl.glVertex3f(2.0f, 1.5f, 3.0f);
+ gl.glVertex3f(2.0f, -1.5f, 3.0f);
+
+ gl.glNormal3f(1.0f, 0.0f, 0.0f);
+ gl.glVertex3f(2.05f, -1.55f, -3.0f);
+ gl.glVertex3f(2.05f, 1.55f, -3.0f);
+ gl.glVertex3f(2.05f, 1.55f, 3.0f);
+ gl.glVertex3f(2.05f, -1.55f, 3.0f);
+
+ gl.glEnd();
+
+ if (texture[1] != null) {
+ texture[1].enable(gl);
+ texture[1].bind(gl);
+ gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+ TextureCoords coords = texture[1].getImageTexCoords();
+
+ /* draw down sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(0.0f, 1.0f, 0.0f);
+ gl.glTexCoord2f(coords.left(), coords.top());
+ gl.glVertex3f(-2.0f, -1.5f, -3.0f);
+ gl.glTexCoord2f(coords.left(), coords.bottom());
+ gl.glVertex3f(-2.0f, -1.5f, 3.0f);
+ gl.glTexCoord2f(coords.right(), coords.bottom());
+ gl.glVertex3f( 2.0f, -1.5f, 3.0f);
+ gl.glTexCoord2f(coords.right(), coords.top());
+ gl.glVertex3f( 2.0f, -1.5f, -3.0f);
+
+ gl.glNormal3f(0.0f, -1.0f, 0.0f);
+ gl.glVertex3f(-2.05f, -1.55f, -3.0f);
+ gl.glVertex3f(-2.05f, -1.55f, 3.0f);
+ gl.glVertex3f( 2.05f, -1.55f, 3.0f);
+ gl.glVertex3f( 2.05f, -1.55f, -3.0f);
+
+ gl.glEnd();
+
+ texture[1].disable(gl);
+ }
+
+ /* draw back sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(0.0f, 0.0f, -1.0f);
+
+ gl.glVertex3f(-2.05f, 1.55f, -3.0f);
+ gl.glVertex3f( 2.05f, 1.55f, -3.0f);
+ gl.glVertex3f( 2.0f, 1.5f, -3.0f);
+ gl.glVertex3f(-2.0f, 1.5f, -3.0f);
+
+ gl.glVertex3f(-2.05f, -1.55f, -3.0f);
+ gl.glVertex3f( 2.05f, -1.55f, -3.0f);
+ gl.glVertex3f( 2.0f, -1.5f, -3.0f);
+ gl.glVertex3f(-2.0f, -1.5f, -3.0f);
+
+ gl.glVertex3f(-2.05f, -1.55f, -3.0f);
+ gl.glVertex3f(-2.05f, 1.55f, -3.0f);
+ gl.glVertex3f(-2.0f, 1.5f, -3.0f);
+ gl.glVertex3f(-2.0f, -1.5f, -3.0f);
+
+ gl.glVertex3f(2.05f, -1.55f, -3.0f);
+ gl.glVertex3f(2.05f, 1.55f, -3.0f);
+ gl.glVertex3f(2.0f, 1.5f, -3.0f);
+ gl.glVertex3f(2.0f, -1.5f, -3.0f);
+
+ gl.glEnd();
+
+ /* draw front sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(0.0f, 0.0f, 1.0f);
+
+ gl.glVertex3f(-2.05f, 1.55f, 3.0f);
+ gl.glVertex3f( 2.05f, 1.55f, 3.0f);
+ gl.glVertex3f( 2.0f, 1.5f, 3.0f);
+ gl.glVertex3f(-2.0f, 1.5f, 3.0f);
+
+ gl.glVertex3f(-2.05f, -1.55f, 3.0f);
+ gl.glVertex3f( 2.05f, -1.55f, 3.0f);
+ gl.glVertex3f( 2.0f, -1.5f, 3.0f);
+ gl.glVertex3f(-2.0f, -1.5f, 3.0f);
+
+ gl.glVertex3f(-2.05f, -1.55f, 3.0f);
+ gl.glVertex3f(-2.05f, 1.55f, 3.0f);
+ gl.glVertex3f(-2.0f, 1.5f, 3.0f);
+ gl.glVertex3f(-2.0f, -1.5f, 3.0f);
+
+ gl.glVertex3f(2.05f, -1.55f, 3.0f);
+ gl.glVertex3f(2.05f, 1.55f, 3.0f);
+ gl.glVertex3f(2.0f, 1.5f, 3.0f);
+ gl.glVertex3f(2.0f, -1.5f, 3.0f);
+
+ gl.glEnd();
+
+ }
+
+ public static void box(GL2 gl) //Usually "box" mean box, but there only one side is enough
+ {
+
+ gl.glShadeModel(GL2.GL_FLAT);
+
+ if (texture[4] != null) {
+ texture[4].enable(gl);
+ texture[4].bind(gl);
+ gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
+ gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
+ gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+
+ /* draw the side */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(0.0f, 0.0f, 1.0f);
+ gl.glTexCoord2f(0, 0);
+ gl.glVertex3f(-8.0f, -8.0f, 0.0f);
+ gl.glTexCoord2f(0, 8.0f);
+ gl.glVertex3f(-8.0f, 8.0f, 0.0f);
+ gl.glTexCoord2f(8.0f, 8.0f);
+ gl.glVertex3f( 8.0f, 8.0f, 0.0f);
+ gl.glTexCoord2f(8.0f, 0);
+ gl.glVertex3f( 8.0f, -8.0f, 0.0f);
+
+ gl.glEnd();
+
+ texture[4].disable(gl);
+ }
+
+ }
+
+ public static void desk(GL2 gl, int two_or_three)
+ {
+
+ int i;
+ float temp1;
+
+ gl.glShadeModel(GL2.GL_FLAT);
+
+ if (texture[two_or_three] != null) {
+ texture[two_or_three].enable(gl);
+ texture[two_or_three].bind(gl);
+ gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT);
+ gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT);
+ gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
+
+ /* draw the front */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+
+ gl.glNormal3f(0.0f, 0.0f, 1.0f);
+ for (i=0; i<25; i++)
+ {
+ temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
+
+ gl.glTexCoord2f((i-12)/40.0f, temp1/4 + 0.75f);
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , 0.01f + temp1/25);
+ gl.glTexCoord2f((i-12)/40.0f, -temp1/4 + 0.25f);
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, 0.01f + temp1/25);
+ }
+
+ gl.glEnd();
+
+ /* draw the back */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+
+ gl.glNormal3f(0.0f, 0.0f, -1.0f);
+ for (i=0; i<25; i++)
+ {
+ temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
+
+ gl.glTexCoord2f((i-12)/40.0f, temp1/4 + 0.75f);
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , -0.01f - temp1/25);
+ gl.glTexCoord2f((i-12)/40.0f, -temp1/4 + 0.25f);
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, -0.01f - temp1/25);
+
+ }
+
+ gl.glEnd();
+
+ texture[2].disable(gl);
+ }
+
+ /* draw the top side */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+
+ gl.glNormal3f(0.0f, 1.0f, 0.0f);
+ for (i=0; i<25; i++)
+ {
+ temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
+
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , -0.01f - temp1/25);
+ gl.glVertex3f((i-12)/40.0f, temp1/10 + 0.1f , 0.01f + temp1/25);
+ }
+
+ gl.glEnd();
+
+ /* draw the bottom side */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+
+ gl.glNormal3f(0.0f, -1.0f, 0.0f);
+ for (i=0; i<25; i++)
+ {
+ temp1 = (float) Math.pow(Math.sin(i/24.0f*Math.PI), 0.4d);
+
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, 0.01f + temp1/25);
+ gl.glVertex3f((i-12)/40.0f, -temp1/10 - 0.1f, -0.01f - temp1/25);
+ }
+
+ gl.glEnd();
+
+ /* draw the left and right sides */
+ gl.glBegin(GL2.GL_QUADS);
+
+ gl.glNormal3f(-1.0f, 0.0f, 0.0f);
+ gl.glVertex3f((-12)/40.0f, -0.1f, 0.01f);
+ gl.glVertex3f((-12)/40.0f, +0.1f, 0.01f);
+ gl.glVertex3f((-12)/40.0f, +0.1f, -0.01f);
+ gl.glVertex3f((-12)/40.0f, -0.1f, -0.01f);
+
+ gl.glNormal3f(1.0f, 0.0f, 0.0f);
+ gl.glVertex3f((+12)/40.0f, -0.1f, 0.01f);
+ gl.glVertex3f((+12)/40.0f, +0.1f, 0.01f);
+ gl.glVertex3f((+12)/40.0f, +0.1f, -0.01f);
+ gl.glVertex3f((+12)/40.0f, -0.1f, -0.01f);
+
+
+ gl.glEnd();
+
+ }
+
+ public static void ball(GL2 gl)
+ {
+
+ int i,j;
+ float y1,y2,r1,r2,x,z;
+
+ gl.glShadeModel(GL2.GL_FLAT);
+
+ /* draw the ball */
+ gl.glBegin(GL2.GL_QUAD_STRIP);
+
+ for (i=0; i<20; i++)
+ {
+ y1 = (float) Math.cos((i)/20.0f*Math.PI)/10;
+ y2 = (float) Math.cos((i+1)/20.0f*Math.PI)/10;
+ r1 = (float) Math.sqrt(Math.abs(0.01f-y1*y1));
+ r2 = (float) Math.sqrt(Math.abs(0.01f-y2*y2));
+
+ for (j=0; j<21; j++)
+ {
+ x = (float) (r1*Math.cos((float)j/21*2.0f*Math.PI));
+ z = (float) (r1*Math.sin((float)j/21*2.0f*Math.PI));
+ gl.glNormal3f(10*x, 10*y1, 10*z);
+ gl.glVertex3f(x, y1, z);
+
+ x = (float) (r2*Math.cos((float)j/21*2.0f*Math.PI));
+ z = (float) (r2*Math.sin((float)j/21*2.0f*Math.PI));
+ gl.glNormal3f(10*x, 10*y2, 10*z);
+ gl.glVertex3f(x, y2, z);
+ }
+ }
+
+ gl.glEnd();
+
+ }
+
+ public void MoveSphere()
+ {
+
+ // Ball out
+
+ if ((BallCz>3)||(BallCz<-3))
+ {
+
+ Vec=BallCz;
+
+ BallCx = 0.0f;
+ BallCy = 0.0f;
+ BallCz = 0.0f;
+
+ spz=0;
+ spx=0;
+ spy=0;
+
+ CanF=false;
+
+ Bax=0;
+ Bay=0;
+
+ }
+
+ // Ball rebound
+
+ if ((spz<0)&&(BallCz+spz<-2.8)&&(BallCx+spx<EnDeskCx+0.3)&&(BallCx+spx>EnDeskCx-0.3)&&(BallCy+spy<EnDeskCy+0.2)&&(BallCy+spy>EnDeskCy-0.2))
+ {
+
+ spz=-spz+0.002f;
+ spx=spx+(BallCx-EnDeskCx)/10;
+ spy=spy+(BallCy-EnDeskCy)/10;
+
+ }
+
+ if ((spz>0)&&(BallCz+spz>2.8)&&(BallCx+spx<sx+0.3)&&(BallCx+spx>sx-0.3)&&(BallCy+spy<sy+0.2)&&(BallCy+spy>sy-0.2))
+ {
+
+ spz=-spz-0.002f;
+ spx=spx+(BallCx-sx)/10;
+ spy=spy+(BallCy-sy)/10;
+
+ Bax=DspeedX/100;
+ Bay=DspeedY/100;
+
+ }
+
+ if ((BallCx+spx<-1.9)||(BallCx+spx>1.9))
+ spx=-spx;
+
+ if ((BallCy+spy<-1.4)||(BallCy+spy>1.4))
+ spy=-spy;
+
+ // Ball acceleration
+
+ spx=spx+Bax;
+ spy=spy+Bay;
+
+ // Ball move
+
+ if (CanF==true)
+
+ BallCx += spx;
+ BallCy += spy;
+ BallCz += spz;
+
+ //Less the acceleration
+
+ Bax=Bax-Bax/100;
+ Bay=Bay-Bay/100;
+
+ }
+
+ public void MoveEnDesk()
+ {
+
+ //Just follow for the ball
+
+ float sx,sy;
+ double gip=Math.sqrt((BallCx-EnDeskCx)*(BallCx-EnDeskCx)+(BallCy-EnDeskCy)*(BallCy-EnDeskCy));
+
+ if (gip<0.07)
+ {
+ sx=Math.abs((BallCx-EnDeskCx));
+ sy=Math.abs((BallCy-EnDeskCy));
+ }
+ else
+ {
+ sx=Math.abs((BallCx-EnDeskCx))/((float) gip)*0.07f;
+ sy=Math.abs((BallCy-EnDeskCy))/((float) gip)*0.07f;
+ }
+
+ if ((BallCx-EnDeskCx>0)&&(EnDeskCx+sx<=1.7))
+ EnDeskCx += sx;
+
+ if ((BallCx-EnDeskCx<0)&&(EnDeskCx-sx>=-1.7))
+ EnDeskCx -= sx;
+
+ if ((BallCy-EnDeskCy>0)&&(EnDeskCy+sy<=1.3))
+ EnDeskCy += sy;
+
+ if ((BallCy-EnDeskCy<0)&&(EnDeskCy-sy>=-1.3))
+ EnDeskCy -= sy;
+
+ }
+
+ public void MovMydesk() {
+
+ LPositionDX = sx;
+ LPositionDY = sy;
+
+ int x = MouseInfo.getPointerInfo().getLocation().x;
+ int y = MouseInfo.getPointerInfo().getLocation().y;
+
+ sx = sx + (float)(x-500.0f)/300.0f;
+ sy = sy + (float)(400.0f-y)/300.0f;
+
+ //Check cube borders
+
+ if (sx<-1.7f || sx>1.7f)
+ {
+ if (sx>0) sx = 1.7f;
+ else sx = -1.7f;
+ }
+
+ if (sy<-1.3 || sy>1.3)
+ {
+ if (sy>0) sy = 1.3f;
+ else sy = -1.3f;
+ }
+
+ //Return the mouse back from screen borders
+ try {
+ Robot r = new Robot();
+ r.mouseMove(500,400);
+ } catch(AWTException ex) {}
+
+ NPositionDX=sx;
+ NPositionDY=sy;
+
+ DspeedX=NPositionDX-LPositionDX;
+ DspeedY=NPositionDY-LPositionDY;
+
+ }
+
+ class TennisKeyAdapter extends KeyAdapter {
+ public void keyPressed(KeyEvent e) {
+ int kc = e.getKeyCode();
+ if(KeyEvent.VK_ESCAPE == kc) {
+ System.exit(0);
+ }
+ if(KeyEvent.VK_CONTROL == kc) {
+ control = false;
+ }
+ if(KeyEvent.VK_SPACE == kc) { //Ready for play
+ if (CanF==false)
+ {
+ if (Vec<0)
+ spz=-0.07f;
+ else
+ spz=0.07f;
+ }
+ CanF=true;
+ }
+ }
+
+ public void keyReleased(KeyEvent e) { //Give the mouse control to the user
+ int kc = e.getKeyCode();
+ if(KeyEvent.VK_CONTROL == kc) {
+ control = true;
+ }
+ }
+
+ }
+
+ class TennisMouseAdapter extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ prevMouseX = e.getX();
+ prevMouseY = e.getY();
+
+ mouseButtonDown = true;
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ mouseButtonDown = false;
+ }
+
+ public void mouseDragged(MouseEvent e) {
+
+ int x = e.getX();
+ int y = e.getY();
+
+ float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)WindowW);
+ float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)WindowH);
+
+ prevMouseX = x;
+ prevMouseY = y;
+
+ view_rotx += thetaX;
+ view_roty += thetaY;
+ }
+ }
+
+}
diff --git a/src/demos/texture/TestSubImage.java b/src/demos/texture/TestSubImage.java index 377a910..05cbb59 100755 --- a/src/demos/texture/TestSubImage.java +++ b/src/demos/texture/TestSubImage.java @@ -120,7 +120,7 @@ public class TestSubImage { if (convertedImage == null) { // Get rid of any previously allocated texture if (texture != null) { - texture.dispose(); + texture.destroy(gl); texture = null; } @@ -183,15 +183,15 @@ public class TestSubImage { yOrigin = texture.getHeight() - yOrigin; } - texture.updateSubImage(textureData, 0, + texture.updateSubImage(gl, textureData, 0, union.x, yOrigin, union.x, yOrigin, union.width, union.height); } // Now draw one quad with the texture - texture.enable(); - texture.bind(); + texture.enable(gl); + texture.bind(gl); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); TextureCoords coords = texture.getImageTexCoords(); gl.glBegin(GL2.GL_QUADS); @@ -204,7 +204,7 @@ public class TestSubImage { gl.glTexCoord2f(coords.left(), coords.top()); gl.glVertex3f(0, 1, 0); gl.glEnd(); - texture.disable(); + texture.disable(gl); } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} diff --git a/src/demos/texture/TestTexture.java b/src/demos/texture/TestTexture.java index 057e957..224c247 100755 --- a/src/demos/texture/TestTexture.java +++ b/src/demos/texture/TestTexture.java @@ -184,7 +184,7 @@ public class TestTexture implements GLEventListener { if (flushTexture) { flushTexture = false; if (texture != null) { - texture.dispose(); + texture.destroy(gl); texture = null; } } @@ -193,7 +193,7 @@ public class TestTexture implements GLEventListener { newTexture = false; if (texture != null) { - texture.dispose(); + texture.destroy(gl); texture = null; } @@ -214,8 +214,8 @@ public class TestTexture implements GLEventListener { } if (texture != null) { - texture.enable(); - texture.bind(); + texture.enable(gl); + texture.bind(gl); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); TextureCoords coords = texture.getImageTexCoords(); @@ -229,7 +229,7 @@ public class TestTexture implements GLEventListener { gl.glTexCoord2f(coords.left(), coords.top()); gl.glVertex3f(0, 1, 0); gl.glEnd(); - texture.disable(); + texture.disable(gl); } } diff --git a/src/demos/texture/TextureConvert.java b/src/demos/texture/TextureConvert.java index 7967416..cd198e0 100755 --- a/src/demos/texture/TextureConvert.java +++ b/src/demos/texture/TextureConvert.java @@ -39,7 +39,7 @@ package demos.texture; -import com.jogamp.opengl.util.FileUtil; +import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; @@ -84,7 +84,7 @@ public class TextureConvert { GL gl = pbuffer.getGL(); boolean attemptCompression = false; - if (TextureIO.DDS.equals(FileUtil.getFileSuffix(outputFile))) { + if (TextureIO.DDS.equals(IOUtil.getFileSuffix(outputFile))) { if (gl.isExtensionAvailable("GL_EXT_texture_compression_s3tc") || gl.isExtensionAvailable("GL_NV_texture_compression_vtc")) { attemptCompression = true; diff --git a/src/demos/util/Cubemap.java b/src/demos/util/Cubemap.java index 9f31b9a..abca371 100755 --- a/src/demos/util/Cubemap.java +++ b/src/demos/util/Cubemap.java @@ -39,7 +39,7 @@ package demos.util; -import com.jogamp.opengl.util.FileUtil; +import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; @@ -62,21 +62,21 @@ public class Cubemap { GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z }; - public static Texture loadFromStreams(ClassLoader scope, + public static Texture loadFromStreams(GL gl, + ClassLoader scope, String basename, - String suffix, - boolean mipmapped) throws IOException, GLException { + String suffix, boolean mipmapped) throws IOException, GLException { Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); for (int i = 0; i < suffixes.length; i++) { String resourceName = basename + suffixes[i] + "." + suffix; TextureData data = TextureIO.newTextureData(GLContext.getCurrentGL().getGLProfile(), scope.getResourceAsStream(resourceName), mipmapped, - FileUtil.getFileSuffix(resourceName)); + IOUtil.getFileSuffix(resourceName)); if (data == null) { throw new IOException("Unable to load texture " + resourceName); } - cubemap.updateImage(data, targets[i]); + cubemap.updateImage(gl, data, targets[i]); } return cubemap; diff --git a/src/demos/util/DurationTimer.java b/src/demos/util/DurationTimer.java index c0f88e7..18a7f40 100644 --- a/src/demos/util/DurationTimer.java +++ b/src/demos/util/DurationTimer.java @@ -58,7 +58,7 @@ public class DurationTimer { accumulatedTime += (curTime - startTime); } - public long getDuration() { + public long getTotalFPSDuration() { return accumulatedTime; } diff --git a/src/demos/vertexProgRefract/VertexProgRefract.java b/src/demos/vertexProgRefract/VertexProgRefract.java index cac8d5a..9915fae 100644 --- a/src/demos/vertexProgRefract/VertexProgRefract.java +++ b/src/demos/vertexProgRefract/VertexProgRefract.java @@ -299,10 +299,10 @@ public class VertexProgRefract extends Demo { gl.glProgramEnvParameter4fARB(GL2.GL_VERTEX_PROGRAM_ARB, 3, 0.0f, 1.0f, 2.0f, 3.0f); // misc constants try { - cubemap = Cubemap.loadFromStreams(getClass().getClassLoader(), + cubemap = Cubemap.loadFromStreams(gl, + getClass().getClassLoader(), "demos/data/cubemaps/uffizi_", - "png", - true); + "png", true); } catch (IOException e) { shutdownDemo(); throw new RuntimeException(e); @@ -403,15 +403,15 @@ public class VertexProgRefract extends Demo { // set texture transforms gl.glActiveTexture(GL.GL_TEXTURE0); - cubemap.bind(); - cubemap.enable(); + cubemap.bind(gl); + cubemap.enable(gl); gl.glMatrixMode(GL.GL_TEXTURE); gl.glLoadIdentity(); viewer.updateInverseRotation(gl); gl.glActiveTexture(GL.GL_TEXTURE1); - cubemap.bind(); - cubemap.enable(); + cubemap.bind(gl); + cubemap.enable(gl); gl.glMatrixMode(GL.GL_TEXTURE); gl.glLoadIdentity(); viewer.updateInverseRotation(gl); @@ -617,8 +617,8 @@ public class VertexProgRefract extends Demo { gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); gl.glActiveTexture(GL.GL_TEXTURE0); - cubemap.bind(); - cubemap.enable(); + cubemap.bind(gl); + cubemap.enable(gl); // This is a workaround for a driver bug on Mac OS X where the // normals are not being sent down to the hardware in diff --git a/src/jbullet/src/javabullet/collision/dispatch/ConvexConvexAlgorithm.java b/src/jbullet/src/javabullet/collision/dispatch/ConvexConvexAlgorithm.java index 6b674c3..08bd8ce 100644 --- a/src/jbullet/src/javabullet/collision/dispatch/ConvexConvexAlgorithm.java +++ b/src/jbullet/src/javabullet/collision/dispatch/ConvexConvexAlgorithm.java @@ -104,7 +104,7 @@ public class ConvexConvexAlgorithm extends CollisionAlgorithm { ConvexShape min1 = (ConvexShape) body1.getCollisionShape(); ClosestPointInput input = pointInputsPool.get(); - input.init(); + input.init(gl); // JAVA NOTE: original: TODO: if (dispatchInfo.m_useContinuous) gjkPairDetector.setMinkowskiA(min0); diff --git a/src/jbullet/src/javabullet/collision/narrowphase/GjkConvexCast.java b/src/jbullet/src/javabullet/collision/narrowphase/GjkConvexCast.java index a5daad0..0e94d54 100644 --- a/src/jbullet/src/javabullet/collision/narrowphase/GjkConvexCast.java +++ b/src/jbullet/src/javabullet/collision/narrowphase/GjkConvexCast.java @@ -113,7 +113,7 @@ public class GjkConvexCast implements ConvexCast { GjkPairDetector gjk = new GjkPairDetector(raySphere, convex, simplexSolver, penSolverPtr); ClosestPointInput input = pointInputsPool.get(); - input.init(); + input.init(gl); input.transformA.set(sphereTr); input.transformB.set(identityTrans); @@ -162,7 +162,7 @@ public class GjkConvexCast implements ConvexCast { GjkPairDetector gjk = new GjkPairDetector(raySphere, convex, simplexSolver, penSolverPtr); ClosestPointInput input = pointInputsPool.get(); - input.init(); + input.init(gl); input.transformA.set(sphereTr); input.transformB.set(identityTrans); diff --git a/src/jbullet/src/javabullet/demos/opengl/JOGL.java b/src/jbullet/src/javabullet/demos/opengl/JOGL.java index 44afa0d..483c652 100644 --- a/src/jbullet/src/javabullet/demos/opengl/JOGL.java +++ b/src/jbullet/src/javabullet/demos/opengl/JOGL.java @@ -101,7 +101,7 @@ public class JOGL implements WindowListener, MouseListener { // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. - window.enablePerfLog(true); + window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err); // Size OpenGL to Video Surface window.setSize(width, height); window.setFullscreen(true); @@ -109,7 +109,7 @@ public class JOGL implements WindowListener, MouseListener { width = window.getWidth(); height = window.getHeight(); - while (!quit && window.getDuration() < 200000) { + while (!quit && window.getTotalFPSDuration() < 200000) { window.display(); } |