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 /src/demos/es1 | |
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
Diffstat (limited to 'src/demos/es1')
-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 |
4 files changed, 89 insertions, 50 deletions
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)) { |