diff options
author | Sven Gothel <[email protected]> | 2008-07-25 16:27:43 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2008-07-25 16:27:43 +0000 |
commit | 0b1b93e201294cad2000247e672f3b27dc5ab52b (patch) | |
tree | cccb2525f0d2c141f657e8f965e9f20605fef43a | |
parent | e3b90ddc82f92c3e10ee732b3b4d8019cbc94190 (diff) |
ES 2:
Working:
demo.es2.RedSquare (gl2/es2 shader+PMVMatrix)
+++
ES2 Fixed Function:
Working on all profiles:
demo.es1.RedSquare
demo.es1.cube.Cube
demo.es1.cubefbo.Main (buggy .. invisible - texture shader problem !)
javabullet.demos.genericjoint.GenericJointDemo (buggy .. invisible !)
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@264 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
-rw-r--r-- | make/build.xml | 7 | ||||
-rw-r--r-- | setenv-jogl.sh | 3 | ||||
-rwxr-xr-x | src/demos/GLInfo.java | 86 | ||||
-rwxr-xr-x | src/demos/es1/RedSquare.java | 41 | ||||
-rw-r--r-- | src/demos/es1/cube/Cube.java | 82 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/FBCubes.java | 14 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/Main.java | 2 | ||||
-rwxr-xr-x | src/demos/es2/RedSquare.java | 311 | ||||
-rw-r--r-- | src/jbullet/setenv-jbullet.sh | 4 | ||||
-rw-r--r-- | src/jbullet/src/javabullet/demos/opengl/DemoApplication.java | 40 | ||||
-rw-r--r-- | src/jbullet/src/javabullet/demos/opengl/GLSRT.java | 10 | ||||
-rw-r--r-- | src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java | 20 | ||||
-rw-r--r-- | src/jbullet/src/javabullet/demos/opengl/JOGL.java | 2 |
13 files changed, 537 insertions, 85 deletions
diff --git a/make/build.xml b/make/build.xml index 12aee25..1f4c4ac 100644 --- a/make/build.xml +++ b/make/build.xml @@ -178,7 +178,7 @@ <pathelement location="${jogl.egl.jar}" /> <pathelement location="${newt.jar}" /> </path> - <javac destdir="${classes}" includes="demos/es1/**" source="1.4" target="1.4" debug="true" debuglevel="source,lines" + <javac destdir="${classes}" includes="demos/GLInfo*, demos/es1/**" source="1.4" target="1.4" debug="true" debuglevel="source,lines" bootclasspath="../../gluegen/make/lib/cdc_fp.jar"> <src path="${src}" /> <classpath refid="jogl-demos.classpath" /> @@ -202,7 +202,10 @@ <pathelement location="${jogl.egl.jar}" /> <pathelement location="${newt.jar}" /> </path> - <javac destdir="${classes}" includes="demos/es2/**" source="1.4" target="1.4" debug="true" debuglevel="source,lines" + <javac destdir="${classes}" + includes="demos/GLInfo*, demos/es2/**" + excludes="demos/es2/Shader*, demos/es2/Basic*" + source="1.4" target="1.4" debug="true" debuglevel="source,lines" bootclasspath="../../gluegen/make/lib/cdc_fp.jar"> <src path="${src}" /> <classpath refid="jogl-demos.classpath" /> diff --git a/setenv-jogl.sh b/setenv-jogl.sh index 2378806..2b0e08e 100644 --- a/setenv-jogl.sh +++ b/setenv-jogl.sh @@ -7,6 +7,8 @@ else JOGL_PROFILE=$1 shift +echo JOGL PROFILE: $JOGL_PROFILE + CVSROOT=":pserver:[email protected]:/cvs" THISDIR=`pwd` export CVSROOT THISDIR @@ -36,6 +38,7 @@ done export CLASSPATH export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GLUEGEN_OS:$THISDIR/../jogl/build/obj +echo JOGL_CLASSPATH: $JOGL_CLASSPATH fi diff --git a/src/demos/GLInfo.java b/src/demos/GLInfo.java new file mode 100755 index 0000000..e670e88 --- /dev/null +++ b/src/demos/GLInfo.java @@ -0,0 +1,86 @@ +package demos; + +import java.nio.*; +import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glu.*; + +import com.sun.javafx.newt.*; + +public class GLInfo implements GLEventListener { + + private GLWindow window; + + private void run(int type) { + int width = 10; + int height = 10; + System.err.println("GLInfo.run()"); + GLProfile.setProfileGLAny(); + try { + Window nWindow = null; + if(0!=(type&USE_AWT)) { + Display nDisplay = NewtFactory.createDisplay(NewtFactory.AWT, null); // local display + Screen nScreen = NewtFactory.createScreen(NewtFactory.AWT, nDisplay, 0); // screen 0 + nWindow = NewtFactory.createWindow(NewtFactory.AWT, nScreen, 0); // dummy VisualID + //nWindow.setVisible(true); + } + + GLCapabilities caps = new GLCapabilities(); + // For emulation library, use 16 bpp + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setDepthBits(16); + window = GLWindow.create(nWindow, caps); + + window.addGLEventListener(this); + + // Size OpenGL to Video Surface + window.setSize(width, height); + window.setFullscreen(true); + window.setVisible(true); + + window.display(); + + // Shut things down cooperatively + window.close(); + window.getFactory().shutdown(); + System.out.println("GLInfo shut down cleanly."); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public void init(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + + System.err.println("GL Profile: "+GLProfile.getProfile()); + System.err.println("GL:" + gl); + System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION)); + System.err.println("GL_EXTENSIONS: "); + System.err.println(" " + gl.glGetString(GL.GL_EXTENSIONS)); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void display(GLAutoDrawable drawable) { + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + public static int USE_NEWT = 0; + public static int USE_AWT = 1 << 0; + + public static void main(String[] args) { + int type = USE_NEWT ; + for(int i=args.length-1; i>=0; i--) { + if(args[i].equals("-awt")) { + type |= USE_AWT; + } + } + new GLInfo().run(type); + System.exit(0); + } +} diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index de8f2b8..cc99db8 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -43,7 +43,7 @@ public class RedSquare implements MouseListener, GLEventListener { int width = 800; int height = 480; System.err.println("RedSquare.run()"); - GLProfile.setProfileGL2ES1(); + GLProfile.setProfileGLAny(); try { Window nWindow = null; if(0!=(type&USE_AWT)) { @@ -95,19 +95,25 @@ public class RedSquare implements MouseListener, GLEventListener { private FloatBuffer vertices; public void init(GLAutoDrawable drawable) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); glu = GLU.createGLU(); System.err.println("Entering initialization"); - System.err.println("GL_VERSION=" + gl.glGetString(GL2ES1.GL_VERSION)); + System.err.println("GL Profile: "+GLProfile.getProfile()); + System.err.println("GL:" + gl); + System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); System.err.println("GL_EXTENSIONS:"); - System.err.println(" " + gl.glGetString(GL2ES1.GL_EXTENSIONS)); + System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); + + if(gl.isGLES2()) { + gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLOR); + } // Allocate vertex arrays colors = BufferUtil.newFloatBuffer(16); vertices = BufferUtil.newFloatBuffer(12); // Fill them up colors.put( 0, 1); colors.put( 1, 0); colors.put( 2, 0); colors.put( 3, 1); - colors.put( 4, 1); colors.put( 5, 0); colors.put( 6, 0); colors.put( 7, 1); + colors.put( 4, 0); colors.put( 5, 0); colors.put( 6, 1); colors.put( 7, 1); colors.put( 8, 1); colors.put( 9, 0); colors.put(10, 0); colors.put(11, 1); colors.put(12, 1); colors.put(13, 0); colors.put(14, 0); colors.put(15, 1); vertices.put(0, -2); vertices.put( 1, 2); vertices.put( 2, 0); @@ -115,37 +121,40 @@ public class RedSquare implements MouseListener, GLEventListener { vertices.put(6, -2); vertices.put( 7, -2); vertices.put( 8, 0); vertices.put(9, 2); vertices.put(10, -2); vertices.put(11, 0); - gl.glEnableClientState(GL2ES1.GL_VERTEX_ARRAY); - gl.glVertexPointer(3, GL2ES1.GL_FLOAT, 0, vertices); - gl.glEnableClientState(GL2ES1.GL_COLOR_ARRAY); - gl.glColorPointer(4, GL2ES1.GL_FLOAT, 0, colors); + gl.glEnableClientState(gl.GL_VERTEX_ARRAY); + gl.glEnableClientState(gl.GL_COLOR_ARRAY); + gl.glVertexPointer(3, gl.GL_FLOAT, 0, vertices); + gl.glColorPointer(4, gl.GL_FLOAT, 0, colors); // OpenGL Render Settings gl.glClearColor(0, 0, 0, 1); - gl.glEnable(GL2ES1.GL_DEPTH_TEST); + gl.glEnable(gl.GL_DEPTH_TEST); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); // Set location in front of camera - gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f); + //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); } public void display(GLAutoDrawable drawable) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); - gl.glClear(GL2ES1.GL_COLOR_BUFFER_BIT | GL2ES1.GL_DEPTH_BUFFER_BIT); + GL gl = drawable.getGL(); + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); // One rotation every four seconds - gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -10); float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f; gl.glRotatef(ang, 0, 0, 1); + gl.glRotatef(ang, 0, 1, 0); + // Draw a square - gl.glDrawArrays(GL2ES1.GL_TRIANGLE_STRIP, 0, 4); + gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java index 910d96b..e9e55cc 100644 --- a/src/demos/es1/cube/Cube.java +++ b/src/demos/es1/cube/Cube.java @@ -51,7 +51,7 @@ public class Cube implements GLEventListener { cubeVertices.put(s_cubeVertices); cubeVertices.flip(); - this.cubeColors = BufferUtil.newByteBuffer(s_cubeColors.length); + this.cubeColors = BufferUtil.newFloatBuffer(s_cubeColors.length); cubeColors.put(s_cubeColors); cubeColors.flip(); @@ -71,15 +71,32 @@ public class Cube implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); glu = GLU.createGLU(); - + if(gl.isGLES2()) { + if( 0 == ( gl.getGLES2().getEnabledFixedFunctionEmulationModes() & GLES2.FIXED_EMULATION_VERTEXCOLOR ) ) { + gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLOR); + System.err.println("Cubes Fixed emu: FIXED_EMULATION_VERTEXCOLOR"); + } + } + if(!innerCube) { + System.err.println("Entering initialization"); + System.err.println("GL Profile: "+GLProfile.getProfile()); + System.err.println("GL:" + gl); + System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); + System.err.println("GL_EXTENSIONS:"); + System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); + } } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { float aspect = (height != 0) ? ((float)width / (float)height) : 1.0f; - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); + GL2ES1 glF=null; + if(gl.isGL2ES1()) { + glF = drawable.getGL().getGL2ES1(); + } gl.glViewport(0, 0, width, height); @@ -99,9 +116,12 @@ public class Cube implements GLEventListener { gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, light_ambient, 0); gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light_diffuse, 0); gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, zero_vec4, 0); - gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, material_spec, 0); + if(null!=glF) { + glF.glMaterialfv(glF.GL_FRONT_AND_BACK, glF.GL_SPECULAR, material_spec, 0); + + glF.glEnable(glF.GL_NORMALIZE); + } - gl.glEnable(gl.GL_NORMALIZE); gl.glEnable(gl.GL_LIGHTING); gl.glEnable(gl.GL_LIGHT0); gl.glEnable(gl.GL_COLOR_MATERIAL); @@ -119,7 +139,9 @@ public class Cube implements GLEventListener { gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); } - gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_FASTEST); + if(null!=glF) { + glF.glHint(glF.GL_PERSPECTIVE_CORRECTION_HINT, glF.GL_FASTEST); + } gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); @@ -133,14 +155,14 @@ public class Cube implements GLEventListener { } public void display(GLAutoDrawable drawable) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); + GL2ES1 glF=null; + if(gl.isGL2ES1()) { + glF = drawable.getGL().getGL2ES1(); + } gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); - // Draw a green square using MIDP - //g.setColor(0, 255, 0); - //g.fillRect(20, 20, width - 40, height - 40); - gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); @@ -149,11 +171,13 @@ public class Cube implements GLEventListener { gl.glRotatef((float)(time * 22.311f), -0.1f, 0.0f, -5.0f); gl.glVertexPointer(3, gl.GL_SHORT, 0, cubeVertices); - gl.glColorPointer(4, gl.GL_UNSIGNED_BYTE, 0, cubeColors); + gl.glColorPointer(4, gl.GL_FLOAT, 0, cubeColors); gl.glNormalPointer(gl.GL_BYTE, 0, cubeNormals); if (cubeTexCoords != null) { gl.glTexCoordPointer(2, gl.GL_SHORT, 0, cubeTexCoords); - gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_INCR); + if(null!=glF) { + glF.glTexEnvi(glF.GL_TEXTURE_ENV, glF.GL_TEXTURE_ENV_MODE, glF.GL_INCR); + } } @@ -177,7 +201,7 @@ public class Cube implements GLEventListener { float time = 0.0f; ShortBuffer cubeVertices; ShortBuffer cubeTexCoords; - ByteBuffer cubeColors; + FloatBuffer cubeColors; ByteBuffer cubeNormals; ByteBuffer cubeIndices; private GLU glu; @@ -211,25 +235,25 @@ public class Cube implements GLEventListener { 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0, }; - private static final byte[] s_cubeColors = + private static final float[] s_cubeColors = { - (byte)40, (byte)80, (byte)160, (byte)255, (byte)40, (byte)80, (byte)160, (byte)255, - (byte)40, (byte)80, (byte)160, (byte)255, (byte)40, (byte)80, (byte)160, (byte)255, + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, - (byte)40, (byte)80, (byte)160, (byte)255, (byte)40, (byte)80, (byte)160, (byte)255, - (byte)40, (byte)80, (byte)160, (byte)255, (byte)40, (byte)80, (byte)160, (byte)255, + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, + 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f, - (byte)128, (byte)128, (byte)128, (byte)255, (byte)128, (byte)128, (byte)128, (byte)255, - (byte)128, (byte)128, (byte)128, (byte)255, (byte)128, (byte)128, (byte)128, (byte)255, + 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f, + 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f, - (byte)128, (byte)128, (byte)128, (byte)255, (byte)128, (byte)128, (byte)128, (byte)255, - (byte)128, (byte)128, (byte)128, (byte)255, (byte)128, (byte)128, (byte)128, (byte)255, + 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f, + 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f, - (byte)255, (byte)110, (byte)10, (byte)255, (byte)255, (byte)110, (byte)10, (byte)255, - (byte)255, (byte)110, (byte)10, (byte)255, (byte)255, (byte)110, (byte)10, (byte)255, + 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f, + 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f, - (byte)255, (byte)70, (byte)60, (byte)255, (byte)255, (byte)70, (byte)60, (byte)255, - (byte)255, (byte)70, (byte)60, (byte)255, (byte)255, (byte)70, (byte)60, (byte)255 + 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f, + 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255 }; private static final byte[] s_cubeIndices = { @@ -259,7 +283,7 @@ public class Cube implements GLEventListener { int width = 800; int height = 480; System.err.println("Cube.run()"); - GLProfile.setProfileGL2ES1(); + GLProfile.setProfileGLAny(); try { Window nWindow = null; if(0!=(type&USE_AWT)) { diff --git a/src/demos/es1/cubefbo/FBCubes.java b/src/demos/es1/cubefbo/FBCubes.java index 1f0215f..632dfed 100755 --- a/src/demos/es1/cubefbo/FBCubes.java +++ b/src/demos/es1/cubefbo/FBCubes.java @@ -52,16 +52,23 @@ class FBCubes implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); + + if(gl.isGLES2()) { + gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLOR | GLES2.FIXED_EMULATION_TEXTURE); + System.err.println("FBCubes Fixed emu: FIXED_EMULATION_VERTEXCOLOR | FIXED_EMULATION_TEXTURE"); + } fbo1.init(gl); + //fbo1.init(gl, GL.GL_RGB, GL.GL_RGB, GL.GL_UNSIGNED_BYTE); + //fbo1.init(gl, GL.GL_RGBA, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); + //fbo1.init(gl, GL.GL_RGBA8, GL2.GL_BGRA, GL2.GL_UNSIGNED_INT_8_8_8_8_REV); cubeInner.init(drawable); cubeOuter.init(drawable); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); cubeOuter.reshape(drawable, x, y, width, height); } @@ -74,7 +81,7 @@ class FBCubes implements GLEventListener { } public void display(GLAutoDrawable drawable) { - GL2ES1 gl = drawable.getGL().getGL2ES1(); + GL gl = drawable.getGL(); fbo1.bind(gl); cubeInner.reshape(drawable, 0, 0, FBO_SIZE, FBO_SIZE); @@ -82,7 +89,6 @@ class FBCubes implements GLEventListener { gl.glFinish(); fbo1.unbind(gl); - gl.glActiveTexture(GL.GL_TEXTURE0); gl.glEnable (gl.GL_TEXTURE_2D); cubeOuter.reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight()); diff --git a/src/demos/es1/cubefbo/Main.java b/src/demos/es1/cubefbo/Main.java index 1d355eb..161d388 100755 --- a/src/demos/es1/cubefbo/Main.java +++ b/src/demos/es1/cubefbo/Main.java @@ -38,7 +38,7 @@ public class Main implements MouseListener { int width = 800; int height = 480; System.out.println("cubefbo.Main.run()"); - GLProfile.setProfileGL2ES1(); + GLProfile.setProfileGLAny(); try { Window nWindow = null; if(0!=(type&USE_AWT)) { diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java new file mode 100755 index 0000000..6b53f04 --- /dev/null +++ b/src/demos/es2/RedSquare.java @@ -0,0 +1,311 @@ +package demos.es2; + +import java.nio.*; +import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glu.*; + +import com.sun.javafx.newt.*; + +public class RedSquare implements MouseListener, GLEventListener { + + private GLWindow window; + private GLU glu; + private boolean quit = false; + private long startTime; + private long curTime; + + public void mouseClicked(MouseEvent e) { + System.out.println("mouseevent: "+e); + switch(e.getClickCount()) { + case 1: + window.setFullscreen(!window.isFullscreen()); + break; + default: + quit=true; + break; + } + } + 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) { + } + + private void run(int type) { + int width = 800; + int height = 480; + System.err.println("RedSquare.run()"); + GLProfile.setProfileGL2ES2(); + try { + Window nWindow = null; + if(0!=(type&USE_AWT)) { + Display nDisplay = NewtFactory.createDisplay(NewtFactory.AWT, null); // local display + Screen nScreen = NewtFactory.createScreen(NewtFactory.AWT, nDisplay, 0); // screen 0 + nWindow = NewtFactory.createWindow(NewtFactory.AWT, nScreen, 0); // dummy VisualID + } + + GLCapabilities caps = new GLCapabilities(); + // For emulation library, use 16 bpp + caps.setRedBits(5); + caps.setGreenBits(6); + caps.setBlueBits(5); + caps.setDepthBits(16); + window = GLWindow.create(nWindow, caps); + + window.addMouseListener(this); + window.addGLEventListener(this); + // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default + // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. + + // Size OpenGL to Video Surface + window.setSize(width, height); + window.setFullscreen(true); + window.setVisible(true); + + startTime = System.currentTimeMillis(); + while (!quit && ((curTime = System.currentTimeMillis()) - startTime) < 20000) { + window.display(); + } + + // Shut things down cooperatively + window.close(); + window.getFactory().shutdown(); + System.out.println("RedSquare shut down cleanly."); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + // FIXME: we must add storage of the pointers in the GL state to + // the GLImpl classes. The need for this can be seen by making + // these variables method local instead of instance members. The + // square will disappear after a second or so due to garbage + // collection. On desktop OpenGL this implies a stack of + // references due to the existence of glPush/PopClientAttrib. On + // OpenGL ES 1/2 it can simply be one set of references. + private FloatBuffer colors; + private FloatBuffer vertices; + + public static final int VERTEX_ARRAY = 0; + public static final int COLOR_ARRAY = 1; + + boolean shaderOk = false; + IntBuffer fragShader = BufferUtil.newIntBuffer(1); + IntBuffer vertShader = BufferUtil.newIntBuffer(1); + int shaderProgram=-1; + int shaderPMVMatrix=-1; + PMVMatrix pmvMatrix; + + public static final String[][] vertShaderSource = new String[][] { { + "#ifdef GL_ES\n"+ + " #define MEDIUMP mediump\n"+ + " #define HIGHP highp\n"+ + "#else\n"+ + " #define MEDIUMP\n"+ + " #define HIGHP\n"+ + "#endif\n"+ + "\n"+ + "uniform MEDIUMP mat4 mgl_PMVMatrix[2];\n"+ + "attribute HIGHP vec4 mgl_Vertex;\n"+ + "attribute HIGHP vec4 mgl_Color;\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "void main(void)\n"+ + "{\n"+ + " frontColor=mgl_Color;\n"+ + " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n"+ + "}\n" } } ; + + public static final String[][] fragShaderSource = new String[][] { { + "#ifdef GL_ES\n"+ + " #define MEDIUMP mediump\n"+ + " #define HIGHP highp\n"+ + "#else\n"+ + " #define MEDIUMP\n"+ + " #define HIGHP\n"+ + "#endif\n"+ + "\n"+ + "varying HIGHP vec4 frontColor;\n"+ + "void main (void)\n"+ + "{\n"+ + " gl_FragColor = frontColor;\n"+ + "}\n" } } ; + + + private void initShader(GL2ES2 gl) { + int tmpI; + + // Create & Compile the vertex shader object + tmpI = gl.glCreateShader(gl.GL_VERTEX_SHADER); + vertShader.put(tmpI); + vertShader.flip(); + + gl.glShaderBinaryOrSource(vertShader, 0, null, vertShaderSource); + gl.glCompileShader(vertShader.get(0)); + if ( ! gl.glIsShaderStatusValid(vertShader.get(0), gl.GL_COMPILE_STATUS) ) { + System.err.println("Failed to compile vertex shader: id "+vertShader.get(0)+ + "\n\t"+gl.glGetShaderInfoLog(vertShader.get(0))); + return; + } + + // Create & Compile the fragment shader object + tmpI = gl.glCreateShader(gl.GL_FRAGMENT_SHADER); + fragShader.put(tmpI); + fragShader.flip(); + + gl.glShaderBinaryOrSource(fragShader, 0, null, fragShaderSource); + + gl.glCompileShader(fragShader.get(0)); + + if ( ! gl.glIsShaderStatusValid(fragShader.get(0), gl.GL_COMPILE_STATUS) ) { + System.err.println("Failed to compile fragment shader: id "+fragShader.get(0)+ + "\n\t"+gl.glGetShaderInfoLog(fragShader.get(0))); + return; + } + + // Create the shader program + shaderProgram = gl.glCreateProgram(); + + // Attach the fragment and vertex shaders to it + gl.glAttachShader(shaderProgram, fragShader.get(0)); + gl.glAttachShader(shaderProgram, vertShader.get(0)); + + gl.glBindAttribLocation(shaderProgram, VERTEX_ARRAY, "mgl_Vertex"); + gl.glBindAttribLocation(shaderProgram, COLOR_ARRAY, "mgl_Color"); + + // Link the program + gl.glLinkProgram(shaderProgram); + + if ( ! gl.glIsProgramValid(shaderProgram, System.err) ) { + return; + } + + gl.glUseProgram(shaderProgram); + + pmvMatrix.glMatrixMode(gl.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glMatrixMode(gl.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + + shaderPMVMatrix = gl.glGetUniformLocation(shaderProgram, "mgl_PMVMatrix"); + if(0<=shaderPMVMatrix) { + gl.glUniformMatrix4fv(shaderPMVMatrix, 2, false, pmvMatrix.glGetPMVMatrixf()); + } else { + System.err.println("could not get uniform mgl_PMVMatrix: "+shaderPMVMatrix); + return; + } + + shaderOk = true; + + } + + public void init(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + glu = GLU.createGLU(); + System.err.println("Entering initialization"); + System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); + System.err.println("GL_EXTENSIONS:"); + System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); + + if(gl.isGLES2()) { + pmvMatrix = gl.getGLES2().getPMVMatrix(); + } else { + pmvMatrix = new PMVMatrix(); + } + + initShader(gl); + + // Allocate vertex arrays + colors = BufferUtil.newFloatBuffer(16); + vertices = BufferUtil.newFloatBuffer(12); + // Fill them up + colors.put( 1); colors.put( 0); colors.put( 0); colors.put( 1); + colors.put( 0); colors.put( 0); colors.put( 1); colors.put( 1); + colors.put( 1); colors.put( 0); colors.put( 0); colors.put( 1); + colors.put( 1); colors.put( 0); colors.put( 0); colors.put( 1); + colors.flip(); + + vertices.put(-2); vertices.put( 2); vertices.put( 0); + vertices.put( 2); vertices.put( 2); vertices.put( 0); + vertices.put(-2); vertices.put( -2); vertices.put( 0); + vertices.put( 2); vertices.put( -2); vertices.put( 0); + vertices.flip(); + + gl.glEnableVertexAttribArray(VERTEX_ARRAY); + gl.glVertexAttribPointer(VERTEX_ARRAY, 3, gl.GL_FLOAT, false, 0, vertices); + + gl.glEnableVertexAttribArray(COLOR_ARRAY); + gl.glVertexAttribPointer(COLOR_ARRAY, 4, gl.GL_FLOAT, false, 0, colors); + + // OpenGL Render Settings + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + + gl.glUseProgram(0); + + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + // Set location in front of camera + pmvMatrix.glMatrixMode(GL2ES2.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0f, (float)width / (float)height, 1.0f, 100.0f); + //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f); + + if(0<=shaderPMVMatrix) { + gl.glUniformMatrix4fv(shaderPMVMatrix, 2, false, pmvMatrix.glGetPMVMatrixf()); + } + } + + public void display(GLAutoDrawable drawable) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glUseProgram(shaderProgram); + + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + + // One rotation every four seconds + pmvMatrix.glMatrixMode(gl.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, -10); + float ang = ((float) (curTime - startTime) * 360.0f) / 4000.0f; + pmvMatrix.glRotatef(ang, 0, 0, 1); + pmvMatrix.glRotatef(ang, 0, 1, 0); + + if(0<=shaderPMVMatrix) { + gl.glUniformMatrix4fv(shaderPMVMatrix, 2, false, pmvMatrix.glGetPMVMatrixf()); + } + + // Draw a square + gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4); + + gl.glUseProgram(0); + + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + public static int USE_NEWT = 0; + public static int USE_AWT = 1 << 0; + + public static void main(String[] args) { + int type = USE_NEWT ; + for(int i=args.length-1; i>=0; i--) { + if(args[i].equals("-awt")) { + type |= USE_AWT; + } + } + new RedSquare().run(type); + System.exit(0); + } +} diff --git a/src/jbullet/setenv-jbullet.sh b/src/jbullet/setenv-jbullet.sh index c61a4cd..2464022 100644 --- a/src/jbullet/setenv-jbullet.sh +++ b/src/jbullet/setenv-jbullet.sh @@ -28,3 +28,7 @@ CLASSPATH_VECM=$LIB/vecmath.jar CLASSPATH=$CLASSPATH:$THISDIR/build/classes:$CLASSPATH_TROVE:$CLASSPATH_VECM export JOGL_HOME CLASSPATH_TROVE CLASSPATH_VECM CLASSPATH +# +# java javabullet.demos.genericjoint.GenericJointDemo +# + diff --git a/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java b/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java index cfd1e23..84678f9 100644 --- a/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java +++ b/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java @@ -137,24 +137,30 @@ public abstract class DemoApplication /* light_position is NOT default value */ float[] light_position0 = new float[] { 1.0f, 10.0f, 1.0f, 0.0f }; float[] light_position1 = new float[] { -1.0f, -10.0f, -1.0f, 0.0f }; - gl = drawable.getGL().getGL2ES1(); + gl = drawable.getGL(); glu = GLU.createGLU(); + + if(gl.isGLES2()) { + gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLOR); + } + glsrt = new GLSRT(glu, gl); - gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, light_ambient, 0); - gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light_diffuse, 0); - gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, light_specular, 0); - gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position0, 0); + gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, light_ambient, 0); + gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, light_diffuse, 0); + gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, light_specular, 0); + gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position0, 0); + + gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, light_ambient, 0); + gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light_diffuse, 0); + gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, light_specular, 0); + gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light_position1, 0); - gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, light_ambient, 0); - gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light_diffuse, 0); - gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, light_specular, 0); - gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, light_position1, 0); + gl.glEnable(gl.GL_LIGHTING); + gl.glEnable(gl.GL_LIGHT0); + gl.glEnable(gl.GL_LIGHT1); - gl.glEnable(gl.GL_LIGHTING); - gl.glEnable(gl.GL_LIGHT0); - gl.glEnable(gl.GL_LIGHT1); + gl.glShadeModel(gl.GL_SMOOTH); - gl.glShadeModel(gl.GL_SMOOTH); gl.glEnable(gl.GL_DEPTH_TEST); gl.glDepthFunc(gl.GL_LESS); @@ -166,7 +172,7 @@ public abstract class DemoApplication } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - gl = drawable.getGL().getGL2ES1(); + gl = drawable.getGL(); glutScreenWidth = width; glutScreenHeight = height; @@ -177,7 +183,7 @@ public abstract class DemoApplication } public void display(GLAutoDrawable drawable) { - gl = drawable.getGL().getGL2ES1(); + gl = drawable.getGL(); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); @@ -208,7 +214,7 @@ public abstract class DemoApplication public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } - protected GL2ES1 gl; + protected GL gl; // // MouseListener @@ -906,7 +912,7 @@ public abstract class DemoApplication float yIncr = 20f; gl.glDisable(gl.GL_LIGHTING); - gl.glColor4f(0f, 0f, 0f, 0f); + // JAU gl.glColor4f(0f, 0f, 0f, 0f); /* if ((debugMode & DebugDrawModes.NO_HELP_TEXT) == 0) { diff --git a/src/jbullet/src/javabullet/demos/opengl/GLSRT.java b/src/jbullet/src/javabullet/demos/opengl/GLSRT.java index 6487664..a026972 100644 --- a/src/jbullet/src/javabullet/demos/opengl/GLSRT.java +++ b/src/jbullet/src/javabullet/demos/opengl/GLSRT.java @@ -44,7 +44,7 @@ public class GLSRT { private GLU glu; // private GLFont font; - public GLSRT(GLU glu, GL2ES1 gl) { + public GLSRT(GLU glu, GL gl) { System.out.println("VBO_CACHE: "+VBO_CACHE); this.glu = glu; /* @@ -62,7 +62,7 @@ public class GLSRT { ImmModeSink vboCube = null; - public void drawCube(GL2ES1 gl, float extent) { + public void drawCube(GL gl, float extent) { extent = extent * 0.5f; if(vboCube==null) { @@ -117,7 +117,7 @@ public class GLSRT { private static Map<SphereKey,ImmModeSink> sphereDisplayLists = new HashMap<SphereKey,ImmModeSink>(); private static SphereKey sphereKey = new SphereKey(); - public void drawSphere(GL2ES1 gl, float radius, int slices, int stacks) { + public void drawSphere(GL gl, float radius, int slices, int stacks) { if(sphere==null) { sphere = glu.gluNewQuadric(); sphere.setImmMode((VBO_CACHE)?false:true); @@ -178,7 +178,7 @@ public class GLSRT { private static Map<CylinderKey,ImmModeSink> cylinderDisplayLists = new HashMap<CylinderKey,ImmModeSink>(); private static CylinderKey cylinderKey = new CylinderKey(); - public void drawCylinder(GL2ES1 gl, float radius, float halfHeight, int upAxis) { + public void drawCylinder(GL gl, float radius, float halfHeight, int upAxis) { if(cylinder==null) { cylinder = glu.gluNewQuadric(); cylinder.setImmMode((VBO_CACHE)?false:true); @@ -226,7 +226,7 @@ public class GLSRT { //////////////////////////////////////////////////////////////////////////// - public void drawString(GL2ES1 gl, CharSequence s, int x, int y, float red, float green, float blue) { + public void drawString(GL gl, CharSequence s, int x, int y, float red, float green, float blue) { /* if (font != null) { FontRender.drawString(gl, font, s, x, y, red, green, blue); diff --git a/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java b/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java index a89ea91..98a4762 100644 --- a/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java +++ b/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java @@ -71,7 +71,7 @@ public class GLShapeDrawer { } */ - public static void drawCoordSystem(GL2ES1 gl) { + public static void drawCoordSystem(GL gl) { ImmModeSink vbo = new ImmModeSink(gl.GL_FLOAT, gl.GL_STATIC_DRAW, 3, 0, 3, 0, 10); vbo.glBegin(gl.GL_LINES); vbo.glColor3f(1, 0, 0); @@ -88,7 +88,7 @@ public class GLShapeDrawer { private static float[] glMat = new float[16]; - public static void drawOpenGL(GLSRT glsrt, GL2ES1 gl, Transform trans, CollisionShape shape, Vector3f color, int debugMode) { + public static void drawOpenGL(GLSRT glsrt, GL gl, Transform trans, CollisionShape shape, Vector3f color, int debugMode) { BulletStack stack = BulletStack.get(); stack.pushCommonMath(); @@ -128,8 +128,8 @@ public class GLShapeDrawer { //glPushMatrix(); - gl.glEnable(gl.GL_COLOR_MATERIAL); - gl.glColor4f(color.x, color.y, color.z, 0f); + gl.glEnable(gl.GL_COLOR_MATERIAL); + gl.glColor4f(color.x, color.y, color.z, 0f); boolean useWireframeFallback = true; @@ -374,13 +374,13 @@ public class GLShapeDrawer { } private static class GlDisplaylistDrawcallback implements TriangleCallback { - private GL2ES1 gl; + private GL gl; private final Vector3f diff1 = new Vector3f(); private final Vector3f diff2 = new Vector3f(); private final Vector3f normal = new Vector3f(); - public GlDisplaylistDrawcallback(GL2ES1 gl) { + public GlDisplaylistDrawcallback(GL gl) { this.gl = gl; } @@ -428,10 +428,10 @@ public class GLShapeDrawer { } private static class GlDrawcallback implements TriangleCallback { - private GL2ES1 gl; + private GL gl; public boolean wireframe = false; - public GlDrawcallback(GL2ES1 gl) { + public GlDrawcallback(GL gl) { this.gl = gl; } @@ -464,9 +464,9 @@ public class GLShapeDrawer { } private static class TriangleGlDrawcallback implements InternalTriangleIndexCallback { - private GL2ES1 gl; + private GL gl; - public TriangleGlDrawcallback(GL2ES1 gl) { + public TriangleGlDrawcallback(GL gl) { this.gl = gl; } diff --git a/src/jbullet/src/javabullet/demos/opengl/JOGL.java b/src/jbullet/src/javabullet/demos/opengl/JOGL.java index 08d9b6b..b302627 100644 --- a/src/jbullet/src/javabullet/demos/opengl/JOGL.java +++ b/src/jbullet/src/javabullet/demos/opengl/JOGL.java @@ -67,7 +67,7 @@ public class JOGL implements MouseListener { int width = 480; int height = 800; System.err.println(title+"run()"); - GLProfile.setProfileGL2ES1(); + GLProfile.setProfileGLAny(); try { Window nWindow = null; if(0!=(type&USE_AWT)) { |