summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2008-08-04 12:19:27 +0000
committerSven Gothel <[email protected]>2008-08-04 12:19:27 +0000
commit673cdf0c7efcba508d441ca74626e6a802b36a23 (patch)
tree29fcbfa4efb974cd3d1235e7ca39ed2d60e9cc4d /src
parent91dab27a9ed3208dbcc9c35170cf3e913418ac13 (diff)
update Cube and jbullet to work with ES20 fixed function pipeline
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@266 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src')
-rwxr-xr-xsrc/demos/es1/RedSquare.java4
-rwxr-xr-xsrc/demos/es1/angeles/AngelesGL2ES1.java8
-rwxr-xr-xsrc/demos/es1/angeles/Main.java5
-rw-r--r--src/demos/es1/cube/Cube.java18
-rw-r--r--src/demos/es1/cube/CubeImmModeSink.java424
-rwxr-xr-xsrc/demos/es1/cubefbo/FBCubes.java4
-rw-r--r--src/jbullet/src/javabullet/demos/opengl/DemoApplication.java32
-rw-r--r--src/jbullet/src/javabullet/demos/opengl/GLSRT.java81
-rw-r--r--src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java87
9 files changed, 593 insertions, 70 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java
index cc99db8..ae6500e 100755
--- a/src/demos/es1/RedSquare.java
+++ b/src/demos/es1/RedSquare.java
@@ -105,7 +105,8 @@ public class RedSquare implements MouseListener, GLEventListener {
System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS));
if(gl.isGLES2()) {
- gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLOR);
+ gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
+ System.err.println("RedSquare Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE");
}
// Allocate vertex arrays
@@ -138,6 +139,7 @@ public class RedSquare implements MouseListener, GLEventListener {
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);
+ //glu.gluLookAt(0, 0, -20, 0, 0, 0, 0, 1, 0);
}
public void display(GLAutoDrawable drawable) {
diff --git a/src/demos/es1/angeles/AngelesGL2ES1.java b/src/demos/es1/angeles/AngelesGL2ES1.java
index ce8fec1..3fe16d4 100755
--- a/src/demos/es1/angeles/AngelesGL2ES1.java
+++ b/src/demos/es1/angeles/AngelesGL2ES1.java
@@ -80,7 +80,11 @@ public class AngelesGL2ES1 implements GLEventListener {
this.gl = drawable.getGL().getGL2ES1();
this.glu = GLU.createGLU();
- gl.glEnable(gl.GL_NORMALIZE);
+ if(gl.isGLES2()) {
+ gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
+ System.err.println("AngelesGL2ES1 Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE");
+ }
+ gl.glEnable(GL2ES1.GL_NORMALIZE);
gl.glEnable(gl.GL_DEPTH_TEST);
gl.glDisable(gl.GL_CULL_FACE);
gl.glShadeModel(gl.GL_FLAT);
@@ -120,7 +124,7 @@ public class AngelesGL2ES1 implements GLEventListener {
gl.glCullFace(GL.GL_FRONT);
- gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST);
+ gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST);
//gl.glShadeModel(GL.GL_SMOOTH);
gl.glShadeModel(gl.GL_FLAT);
diff --git a/src/demos/es1/angeles/Main.java b/src/demos/es1/angeles/Main.java
index aab344e..d5073c7 100755
--- a/src/demos/es1/angeles/Main.java
+++ b/src/demos/es1/angeles/Main.java
@@ -39,7 +39,8 @@ public class Main implements MouseListener {
int width = 800;
int height = 480;
System.out.println("angeles.Main.run()");
- GLProfile.setProfileGL2ES1();
+ //GLProfile.setProfileGL2ES1();
+ GLProfile.setProfileGLAny();
try {
Window nWindow = null;
if(0!=(type&USE_AWT)) {
@@ -74,7 +75,7 @@ public class Main implements MouseListener {
window.addGLEventListener(angel);
} else {
System.out.println("Using: nop .. ");
- }
+ }
long startTime = System.currentTimeMillis();
long lastTime = startTime, curTime = 0, dt0, dt1;
diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java
index bbfbb35..dadc8bc 100644
--- a/src/demos/es1/cube/Cube.java
+++ b/src/demos/es1/cube/Cube.java
@@ -74,10 +74,8 @@ public class Cube implements GLEventListener {
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 | GLES2.FIXED_EMULATION_TEXTURE);
- System.err.println("Cubes Fixed emu: FIXED_EMULATION_VERTEXCOLOR | FIXED_EMULATION_TEXTURE");
- }
+ gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
+ System.err.println("Cubes Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE");
}
if(!innerCube) {
System.err.println("Entering initialization");
@@ -112,19 +110,21 @@ public class Cube implements GLEventListener {
gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
+ if(!innerCube) {
gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position, 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, zero_vec4, 0);
- if(null!=glF) {
- glF.glMaterialfv(glF.GL_FRONT_AND_BACK, glF.GL_SPECULAR, material_spec, 0);
-
- glF.glEnable(glF.GL_NORMALIZE);
- }
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, material_spec, 0);
gl.glEnable(gl.GL_LIGHTING);
gl.glEnable(gl.GL_LIGHT0);
gl.glEnable(gl.GL_COLOR_MATERIAL);
+ } else {
+ gl.glDisable(gl.GL_LIGHTING);
+ gl.glDisable(gl.GL_LIGHT0);
+ }
+ gl.glEnable(gl.GL_NORMALIZE);
gl.glEnable(gl.GL_CULL_FACE);
gl.glShadeModel(gl.GL_SMOOTH);
diff --git a/src/demos/es1/cube/CubeImmModeSink.java b/src/demos/es1/cube/CubeImmModeSink.java
new file mode 100644
index 0000000..e686529
--- /dev/null
+++ b/src/demos/es1/cube/CubeImmModeSink.java
@@ -0,0 +1,424 @@
+/*
+ *
+ * Copyright (c) 2007, Sun Microsystems, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Sun Microsystems nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package demos.es1.cube;
+
+import javax.media.opengl.*;
+import javax.media.opengl.util.*;
+import javax.media.opengl.glu.*;
+import java.nio.*;
+
+import com.sun.javafx.newt.*;
+
+public class CubeImmModeSink implements GLEventListener {
+ public CubeImmModeSink () {
+ this(false, false);
+ }
+
+
+ ByteBuffer cubeIndices=null;
+ ImmModeSink vboCubeF = null;
+ public void drawCube(GL gl, float extent) {
+ if(cubeIndices==null) {
+ cubeIndices = BufferUtil.newByteBuffer(s_cubeIndices);
+ }
+
+ if(vboCubeF==null) {
+ ImmModeSink vbo = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 36,
+ 3, GL.GL_SHORT, // vertex
+ 4, GL.GL_FLOAT, // color
+ 3, GL.GL_BYTE, // normal
+ 0, GL.GL_FLOAT); // texture
+
+ vbo.glBegin(GL.GL_TRIANGLES);
+
+ vbo.glVertexv(BufferUtil.newShortBuffer(s_cubeVertices));
+ vbo.glColorv(BufferUtil.newFloatBuffer(s_cubeColors));
+ vbo.glNormalv(BufferUtil.newByteBuffer(s_cubeNormals));
+
+ if(VBO_CACHE) {
+ vbo.glEnd(gl, false);
+ } else {
+ vbo.glEnd(gl, cubeIndices);
+ }
+ System.err.println("VBO Cube");
+ System.err.println(vbo);
+ if(VBO_CACHE) {
+ vboCubeF = vbo;
+ }
+ }
+ if(null!=vboCubeF) {
+ vboCubeF.draw(gl, cubeIndices, true);
+ }
+ }
+
+ private GLUquadric sphere=null;
+ private ImmModeSink vboSphere=null;
+ public void drawSphere(GL gl, float radius, int slices, int stacks) {
+ if(sphere==null) {
+ sphere = glu.gluNewQuadric();
+ sphere.setImmMode((VBO_CACHE)?false:true);
+ }
+ ImmModeSink vbo = vboSphere;
+ if (vbo == null) {
+ glu.gluSphere(sphere, radius, 8, 8);
+ if(VBO_CACHE) {
+ vboSphere = sphere.replaceImmModeSink();
+ vbo = vboSphere;
+ }
+ System.err.println("VBO Sphere");
+ System.err.println(vbo);
+ }
+
+ if(VBO_CACHE && null!=vbo) {
+ vbo.draw(gl, true);
+ }
+ }
+
+
+ private static boolean VBO_CACHE = true;
+ private GLUquadric cylinder=null;
+ private ImmModeSink vboCylinder=null;
+ public void drawCylinder(GL gl, float radius, float halfHeight, int upAxis) {
+ if(cylinder==null) {
+ cylinder = glu.gluNewQuadric();
+ cylinder.setImmMode((VBO_CACHE)?false:true);
+ }
+
+ gl.glPushMatrix();
+ switch (upAxis) {
+ case 0:
+ gl.glRotatef(-90f, 0.0f, 1.0f, 0.0f);
+ gl.glTranslatef(0.0f, 0.0f, -halfHeight);
+ break;
+ case 1:
+ gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
+ gl.glTranslatef(0.0f, 0.0f, -halfHeight);
+ break;
+ case 2:
+ gl.glTranslatef(0.0f, 0.0f, -halfHeight);
+ break;
+ default: {
+ assert (false);
+ }
+ }
+
+ ImmModeSink vbo = vboCylinder;
+ if (vbo == null) {
+ glu.gluQuadricDrawStyle(cylinder, glu.GLU_FILL);
+ glu.gluQuadricNormals(cylinder, glu.GLU_SMOOTH);
+ glu.gluCylinder(cylinder, radius, radius, 2f * halfHeight, 15, 10);
+ if(VBO_CACHE) {
+ vboCylinder = cylinder.replaceImmModeSink();
+ vbo = vboCylinder;
+ }
+ System.err.println("VBO Cylinder");
+ System.err.println(vbo);
+ }
+
+ if(VBO_CACHE && null!=vbo) {
+ vbo.draw(gl, true);
+ }
+
+ gl.glPopMatrix();
+ }
+
+
+
+ public CubeImmModeSink (boolean useTexCoords, boolean innerCube) {
+ this.innerCube = innerCube;
+ this.useTexCoords = useTexCoords;
+ }
+
+ public void init(GLAutoDrawable drawable) {
+ GL gl = drawable.getGL();
+ glu = GLU.createGLU();
+ if(gl.isGLES2()) {
+ gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
+ System.err.println("CubeImmModeSink Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE");
+ }
+ 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;
+
+ GL gl = drawable.getGL();
+ GL2ES1 glF=null;
+ if(gl.isGL2ES1()) {
+ glF = drawable.getGL().getGL2ES1();
+ }
+
+ gl.glViewport(0, 0, width, height);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glScissor(0, 0, width, height);
+ if(innerCube) {
+ // Clear background to white
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.6f);
+ } else {
+ // Clear background to blue
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, light_position, 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, zero_vec4, 0);
+ gl.glMaterialfv(glF.GL_FRONT_AND_BACK, glF.GL_SPECULAR, material_spec, 0);
+ gl.glEnable(glF.GL_NORMALIZE);
+
+ gl.glEnable(gl.GL_LIGHTING);
+ gl.glEnable(gl.GL_LIGHT0);
+ gl.glEnable(gl.GL_COLOR_MATERIAL);
+ gl.glEnable(gl.GL_CULL_FACE);
+
+ gl.glShadeModel(gl.GL_SMOOTH);
+ gl.glDisable(gl.GL_DITHER);
+
+ if(null!=glF) {
+ glF.glHint(glF.GL_PERSPECTIVE_CORRECTION_HINT, glF.GL_FASTEST);
+ }
+
+ gl.glMatrixMode(gl.GL_PROJECTION);
+ gl.glLoadIdentity();
+
+ if(!innerCube) {
+ glu.gluPerspective(90.0f, aspect, 1.0f, 100.0f);
+ } else {
+ gl.glOrthof(-20.0f, 20.0f, -20.0f, 20.0f, 1.0f, 40.0f);
+ }
+ // weird effect ..: gl.glCullFace(gl.GL_FRONT);
+ }
+
+ public void display(GLAutoDrawable drawable) {
+ 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);
+
+ gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
+
+ gl.glTranslatef(0.f, 0.0f, -30.f);
+ gl.glRotatef((float)(time * 29.77f), 1.0f, 2.0f, 0.0f);
+ gl.glRotatef((float)(time * 22.311f), -0.1f, 0.0f, -5.0f);
+
+ gl.glColor4f(0f, 0f, 0f, 1f);
+
+ if(true) {
+ //gl.glColor4f(1f, 0f, 0f, 1f); // RED inside the color4f's
+ drawCube(gl, 10.0f);
+ }
+
+ if(true) {
+ gl.glColor4f(0f, 1f, 0f, 1f);
+ gl.glPushMatrix();
+ gl.glTranslatef(15.0f, 0.0f, 0.0f);
+ drawSphere(gl, 5.0f, 10, 10);
+ gl.glPopMatrix();
+ }
+
+ if(true) {
+ gl.glColor4f(0f, 0f, 1f, 1f);
+ gl.glPushMatrix();
+ gl.glMultMatrixf(identity4x4f, 0);
+ drawCylinder(gl, 4.0f, 10.0f, 1);
+ gl.glPopMatrix();
+ }
+
+ frameNum++;
+ time += 0.01f;
+ }
+ int frameNum=0;
+
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
+ }
+
+ static final float[] light_position = { -50.f, 50.f, 50.f, 0.f };
+ static final float[] light_ambient = { 0.125f, 0.125f, 0.125f, 1.f };
+ static final float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.f };
+ static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f };
+ static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f };
+ static final float[] identity4x4f = { 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f };
+ private static final short[] s_cubeVertices =
+ {
+ -10, 10, 10, 10, -10, 10, 10, 10, 10, -10, -10, 10,
+
+ -10, 10, -10, 10, -10, -10, 10, 10, -10, -10, -10, -10,
+
+ -10, -10, 10, 10, -10, -10, 10, -10, 10, -10, -10, -10,
+
+ -10, 10, 10, 10, 10, -10, 10, 10, 10, -10, 10, -10,
+
+ 10, -10, 10, 10, 10, -10, 10, 10, 10, 10, -10, -10,
+
+ -10, -10, 10, -10, 10, -10, -10, 10, 10, -10, -10, -10
+ };
+ private static final short[] s_cubeTexCoords =
+ {
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+
+ 0, (short) 0xffff, (short) 0xffff, 0, (short) 0xffff, (short) 0xffff, 0, 0,
+ };
+
+ private static final float[] s_cubeColors =
+ {
+ 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,
+
+ 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,
+
+ 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,
+
+ 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,
+
+ 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,
+
+ 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 =
+ {
+ 0, 3, 1, 2, 0, 1, /* front */
+ 6, 5, 4, 5, 7, 4, /* back */
+ 8, 11, 9, 10, 8, 9, /* top */
+ 15, 12, 13, 12, 14, 13, /* bottom */
+ 16, 19, 17, 18, 16, 17, /* right */
+ 23, 20, 21, 20, 22, 21 /* left */
+ };
+ private static final byte[] s_cubeNormals =
+ {
+ 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127,
+
+ 0, 0, -128, 0, 0, -128, 0, 0, -128, 0, 0, -128,
+
+ 0, -128, 0, 0, -128, 0, 0, -128, 0, 0, -128, 0,
+
+ 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0,
+
+ 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,
+
+ -128, 0, 0, -128, 0, 0, -128, 0, 0, -128, 0, 0
+ };
+
+
+ boolean innerCube;
+ boolean useTexCoords;
+ boolean initialized = false;
+ float time = 0.0f;
+ private GLU glu;
+
+ private void run(int type) {
+ int width = 800;
+ int height = 480;
+ System.err.println("CubeImmModeSink.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
+ }
+
+ GLCapabilities caps = new GLCapabilities();
+ // For emulation library, use 16 bpp
+ caps.setRedBits(5);
+ caps.setGreenBits(6);
+ caps.setBlueBits(5);
+ caps.setDepthBits(16);
+ GLWindow window = GLWindow.create(nWindow, caps);
+
+ window.addGLEventListener(this);
+
+ // Size OpenGL to Video Surface
+ window.setSize(width, height);
+ window.setFullscreen(true);
+ window.setVisible(true);
+
+ long curTime;
+ long startTime = System.currentTimeMillis();
+ while (((curTime = System.currentTimeMillis()) - startTime) < 20000) {
+ window.display();
+ }
+
+ // Shut things down cooperatively
+ window.close();
+ window.getFactory().shutdown();
+ System.out.println("CubeImmModeSink shut down cleanly.");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ 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 CubeImmModeSink().run(type);
+ System.exit(0);
+ }
+}
+
diff --git a/src/demos/es1/cubefbo/FBCubes.java b/src/demos/es1/cubefbo/FBCubes.java
index 632dfed..5478743 100755
--- a/src/demos/es1/cubefbo/FBCubes.java
+++ b/src/demos/es1/cubefbo/FBCubes.java
@@ -55,8 +55,8 @@ class FBCubes implements GLEventListener {
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");
+ gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
+ System.err.println("FBCubes Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE");
}
fbo1.init(gl);
diff --git a/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java b/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java
index 84678f9..5dfc0db 100644
--- a/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java
+++ b/src/jbullet/src/javabullet/demos/opengl/DemoApplication.java
@@ -141,9 +141,16 @@ public abstract class DemoApplication
glu = GLU.createGLU();
if(gl.isGLES2()) {
- gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLOR);
+ gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE);
}
+ 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));
+
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);
@@ -176,7 +183,7 @@ public abstract class DemoApplication
glutScreenWidth = width;
glutScreenHeight = height;
- gl.glViewport(x, y, width, height);
+ //gl.glViewport(x, y, width, height);
updateCamera();
System.out.println("DemoApplication RESHAPE");
@@ -319,6 +326,7 @@ public abstract class DemoApplication
cameraTargetPosition.x, cameraTargetPosition.y, cameraTargetPosition.z,
cameraUp.x, cameraUp.y, cameraUp.z);
gl.glMatrixMode(gl.GL_MODELVIEW);
+ gl.glLoadIdentity();
}
finally {
stack.vectors.pop();
@@ -839,6 +847,7 @@ public abstract class DemoApplication
gl.glMatrixMode(gl.GL_MODELVIEW);
}
+ /**
public void resetPerspectiveProjection() {
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glPopMatrix();
@@ -851,6 +860,7 @@ public abstract class DemoApplication
}
// TODO: protected void showProfileInfo(float& xOffset,float& yStart, float yIncr);
+ */
private final Transform m = new Transform();
private Vector3f wireColor = new Vector3f();
@@ -870,12 +880,15 @@ public abstract class DemoApplication
if (body != null && body.getMotionState() != null) {
DefaultMotionState myMotionState = (DefaultMotionState) body.getMotionState();
m.set(myMotionState.graphicsWorldTrans);
- }
- else {
+ } else {
m.set(colObj.getWorldTransform());
}
- wireColor.set(1f, 1f, 0.5f); // wants deactivation
+ if(0==i) {
+ wireColor.set(0.5f, 1f, 0.5f); // wants deactivation
+ } else {
+ wireColor.set(1f, 1f, 0.5f); // wants deactivation
+ }
if ((i & 1) != 0) {
wireColor.set(0f, 0f, 1f);
}
@@ -904,8 +917,17 @@ public abstract class DemoApplication
}
}
+ // draw (saves the matrix already ..)
GLShapeDrawer.drawOpenGL(glsrt, gl, m, colObj.getCollisionShape(), wireColor, getDebugMode());
}
+ GLShapeDrawer.drawCoordSystem(gl);
+ if(false) {
+ System.err.println("++++++++++++++++++++++++++++++++");
+ System.err.println("++++++++++++++++++++++++++++++++");
+ try {
+ Thread.sleep(2000);
+ } catch (Exception e) {}
+ }
float xOffset = 10f;
float yStart = 20f;
diff --git a/src/jbullet/src/javabullet/demos/opengl/GLSRT.java b/src/jbullet/src/javabullet/demos/opengl/GLSRT.java
index a026972..fb5aa38 100644
--- a/src/jbullet/src/javabullet/demos/opengl/GLSRT.java
+++ b/src/jbullet/src/javabullet/demos/opengl/GLSRT.java
@@ -26,12 +26,14 @@ package javabullet.demos.opengl;
import java.net.URL;
import java.io.IOException;
import java.nio.FloatBuffer;
+import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
// import javabullet.demos.opengl.FontRender.GLFont;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import javax.media.opengl.util.ImmModeSink;
+import javax.media.opengl.util.BufferUtil;
/**
*
@@ -39,7 +41,8 @@ import javax.media.opengl.util.ImmModeSink;
*/
public class GLSRT {
- public static final boolean VBO_CACHE = true;
+ public static final boolean VBO_CACHE = true; // JAU
+ // public static final boolean VBO_CACHE = false;
private GLU glu;
// private GLFont font;
@@ -66,25 +69,75 @@ public class GLSRT {
extent = extent * 0.5f;
if(vboCube==null) {
- vboCube = new ImmModeSink(GL.GL_FLOAT, GL.GL_STATIC_DRAW, 3, 3, 0, 0, 24);
+ vboCube = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 24,
+ 3, GL.GL_FLOAT, // vertex
+ 0, GL.GL_FLOAT, // color
+ 3, GL.GL_FLOAT, // normal
+ 0, GL.GL_FLOAT); // texture
- vboCube.glBegin(ImmModeSink.GL_QUADS);
- vboCube.glNormal3f( 1f, 0f, 0f);
- vboCube.glVertex3f(+extent,-extent,+extent); vboCube.glVertex3f(+extent,-extent,-extent); vboCube.glVertex3f(+extent,+extent,-extent); vboCube.glVertex3f(+extent,+extent,+extent);
- vboCube.glNormal3f( 0f, 1f, 0f);
- vboCube.glVertex3f(+extent,+extent,+extent); vboCube.glVertex3f(+extent,+extent,-extent); vboCube.glVertex3f(-extent,+extent,-extent); vboCube.glVertex3f(-extent,+extent,+extent);
+ vboCube.glBegin(GL.GL_TRIANGLES);
vboCube.glNormal3f( 0f, 0f, 1f);
- vboCube.glVertex3f(+extent,+extent,+extent); vboCube.glVertex3f(-extent,+extent,+extent); vboCube.glVertex3f(-extent,-extent,+extent); vboCube.glVertex3f(+extent,-extent,+extent);
- vboCube.glNormal3f(-1f, 0f, 0f);
- vboCube.glVertex3f(-extent,-extent,+extent); vboCube.glVertex3f(-extent,+extent,+extent); vboCube.glVertex3f(-extent,+extent,-extent); vboCube.glVertex3f(-extent,-extent,-extent);
- vboCube.glNormal3f( 0f,-1f, 0f);
- vboCube.glVertex3f(-extent,-extent,+extent); vboCube.glVertex3f(-extent,-extent,-extent); vboCube.glVertex3f(+extent,-extent,-extent); vboCube.glVertex3f(+extent,-extent,+extent);
+ vboCube.glNormal3f( 0f, 0f, 1f);
+ vboCube.glNormal3f( 0f, 0f, 1f);
+ vboCube.glNormal3f( 0f, 0f, 1f);
+ vboCube.glVertex3f(-extent,+extent,+extent);
+ vboCube.glVertex3f(+extent,-extent,+extent);
+ vboCube.glVertex3f(+extent,+extent,+extent);
+ vboCube.glVertex3f(-extent,-extent,+extent);
+ vboCube.glNormal3f( 0f, 0f,-1f);
+ vboCube.glNormal3f( 0f, 0f,-1f);
+ vboCube.glNormal3f( 0f, 0f,-1f);
vboCube.glNormal3f( 0f, 0f,-1f);
- vboCube.glVertex3f(-extent,-extent,-extent); vboCube.glVertex3f(-extent,+extent,-extent); vboCube.glVertex3f(+extent,+extent,-extent); vboCube.glVertex3f(+extent,-extent,-extent);
+ vboCube.glVertex3f(-extent,+extent,-extent);
+ vboCube.glVertex3f(+extent,-extent,-extent);
+ vboCube.glVertex3f(+extent,+extent,-extent);
+ vboCube.glVertex3f(+extent,+extent,+extent);
+ vboCube.glNormal3f( 0f, -1f, 0f);
+ vboCube.glNormal3f( 0f, -1f, 0f);
+ vboCube.glNormal3f( 0f, -1f, 0f);
+ vboCube.glNormal3f( 0f, -1f, 0f);
+ vboCube.glVertex3f(-extent,-extent,+extent);
+ vboCube.glVertex3f(+extent,-extent,-extent);
+ vboCube.glVertex3f(+extent,-extent,+extent);
+ vboCube.glVertex3f(-extent,-extent,-extent);
+ vboCube.glNormal3f( 0f,1f, 0f);
+ vboCube.glNormal3f( 0f,1f, 0f);
+ vboCube.glNormal3f( 0f,1f, 0f);
+ vboCube.glNormal3f( 0f,1f, 0f);
+ vboCube.glVertex3f(-extent,+extent,+extent);
+ vboCube.glVertex3f(+extent,+extent,-extent);
+ vboCube.glVertex3f(+extent,+extent,+extent);
+ vboCube.glVertex3f(-extent,+extent,-extent);
+ vboCube.glNormal3f( 1f,0f, 0f);
+ vboCube.glNormal3f( 1f,0f, 0f);
+ vboCube.glNormal3f( 1f,0f, 0f);
+ vboCube.glNormal3f( 1f,0f, 0f);
+ vboCube.glVertex3f(+extent,-extent,+extent);
+ vboCube.glVertex3f(+extent,+extent,-extent);
+ vboCube.glVertex3f(+extent,+extent,+extent);
+ vboCube.glVertex3f(+extent,-extent,-extent);
+ vboCube.glNormal3f( -1f, 0f, 0f);
+ vboCube.glNormal3f( -1f, 0f, 0f);
+ vboCube.glNormal3f( -1f, 0f, 0f);
+ vboCube.glNormal3f( -1f, 0f, 0f);
+ vboCube.glVertex3f(-extent,-extent,+extent);
+ vboCube.glVertex3f(-extent,+extent,-extent);
+ vboCube.glVertex3f(-extent,+extent,+extent);
+ vboCube.glVertex3f(-extent,-extent,-extent);
vboCube.glEnd(gl, false);
}
- vboCube.draw(gl, true);
+ vboCube.draw(gl, cubeIndices, true);
}
+ private static final byte[] s_cubeIndices =
+ {
+ 0, 3, 1, 2, 0, 1, /* front */
+ 6, 5, 4, 5, 7, 4, /* back */
+ 8, 11, 9, 10, 8, 9, /* top */
+ 15, 12, 13, 12, 14, 13, /* bottom */
+ 16, 19, 17, 18, 16, 17, /* right */
+ 23, 20, 21, 20, 22, 21 /* left */
+ };
+ private ByteBuffer cubeIndices=BufferUtil.newByteBuffer(s_cubeIndices);
////////////////////////////////////////////////////////////////////////////
diff --git a/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java b/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java
index 98a4762..74ae73c 100644
--- a/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java
+++ b/src/jbullet/src/javabullet/demos/opengl/GLShapeDrawer.java
@@ -72,17 +72,24 @@ public class GLShapeDrawer {
*/
public static void drawCoordSystem(GL gl) {
- ImmModeSink vbo = new ImmModeSink(gl.GL_FLOAT, gl.GL_STATIC_DRAW, 3, 0, 3, 0, 10);
+ ImmModeSink vbo = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 10,
+ 3, GL.GL_FLOAT, // vertex
+ 4, GL.GL_FLOAT, // color
+ 0, GL.GL_FLOAT, // normal
+ 0, GL.GL_FLOAT); // texture
vbo.glBegin(gl.GL_LINES);
- vbo.glColor3f(1, 0, 0);
- vbo.glVertex3f(0, 0, 0);
- vbo.glVertex3f(1, 0, 0);
- vbo.glColor3f(0, 1, 0);
- vbo.glVertex3f(0, 0, 0);
- vbo.glVertex3f(0, 1, 0);
- vbo.glColor3f(0, 0, 1);
- vbo.glVertex3f(0, 0, 0);
- vbo.glVertex3f(0, 0, 1);
+ vbo.glColor4f ( 1f, 1f, 1f, 1f);
+ vbo.glVertex3f( 0f, 0f, 0f);
+ vbo.glColor4f ( 1f, 1f, 1f, 1f);
+ vbo.glVertex3f( 1f, 0f, 0f);
+ vbo.glColor4f ( 1f, 1f, 1f, 1f);
+ vbo.glVertex3f( 0f, 0f, 0f);
+ vbo.glColor4f ( 1f, 1f, 1f, 1f);
+ vbo.glVertex3f( 0f, 1f, 0f);
+ vbo.glColor4f ( 1f, 1f, 1f, 1f);
+ vbo.glVertex3f( 0f, 0f, 0f);
+ vbo.glColor4f ( 1f, 1f, 1f, 1f);
+ vbo.glVertex3f( 0f, 0f, 1f);
vbo.glEnd(gl);
}
@@ -111,7 +118,6 @@ public class GLShapeDrawer {
//
// drawOpenGL( (btScalar*)tmpScaling,convexShape,color,debugMode);
// }
- // glPopMatrix();
// return;
// }
@@ -124,16 +130,12 @@ public class GLShapeDrawer {
}
}
else {
- //drawCoordSystem();
-
- //glPushMatrix();
-
gl.glEnable(gl.GL_COLOR_MATERIAL);
- gl.glColor4f(color.x, color.y, color.z, 0f);
+ gl.glColor4f(color.x, color.y, color.z, 1f);
boolean useWireframeFallback = true;
- if ((debugMode & DebugDrawModes.DRAW_WIREFRAME) == 0) {
+ if ( (debugMode & DebugDrawModes.DRAW_WIREFRAME) == 0) {
switch (shape.getShapeType()) {
case BOX_SHAPE_PROXYTYPE: {
BoxShape boxShape = (BoxShape) shape;
@@ -249,7 +251,11 @@ public class GLShapeDrawer {
if (shape.isPolyhedral()) {
PolyhedralConvexShape polyshape = (PolyhedralConvexShape) shape;
- ImmModeSink vbo = new ImmModeSink(gl.GL_FLOAT, gl.GL_STATIC_DRAW, 3, 0, 0, 0, polyshape.getNumEdges());
+ ImmModeSink vbo = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, polyshape.getNumEdges()+3,
+ 3, GL.GL_FLOAT, // vertex
+ 0, GL.GL_FLOAT, // color
+ 0, GL.GL_FLOAT, // normal
+ 0, GL.GL_FLOAT); // texture
vbo.glBegin(gl.GL_LINES);
@@ -357,11 +363,10 @@ public class GLShapeDrawer {
}
//gl.glEnable(GL_DEPTH_TEST);
- //glPopMatrix();
}
- gl.glPopMatrix();
}
finally {
+ gl.glPopMatrix();
stack.popCommonMath();
}
}
@@ -391,18 +396,22 @@ public class GLShapeDrawer {
normal.normalize();
- ImmModeSink vbo = new ImmModeSink(gl.GL_FLOAT, gl.GL_STATIC_DRAW, 3, 3, 3, 0, 3);
+ ImmModeSink vbo = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 3,
+ 3, GL.GL_FLOAT, // vertex
+ 4, GL.GL_FLOAT, // color
+ 3, GL.GL_FLOAT, // normal
+ 0, GL.GL_FLOAT); // texture
vbo.glBegin(gl.GL_TRIANGLES);
- vbo.glColor3f(0, 1, 0);
+ vbo.glColor4f(0, 1f, 0, 1f);
vbo.glNormal3f(normal.x, normal.y, normal.z);
vbo.glVertex3f(triangle[0].x, triangle[0].y, triangle[0].z);
- vbo.glColor3f(0, 1, 0);
+ vbo.glColor4f(0, 1f, 0, 1f);
vbo.glNormal3f(normal.x, normal.y, normal.z);
vbo.glVertex3f(triangle[1].x, triangle[1].y, triangle[1].z);
- vbo.glColor3f(0, 1, 0);
+ vbo.glColor4f(0, 1f, 0, 1f);
vbo.glNormal3f(normal.x, normal.y, normal.z);
vbo.glVertex3f(triangle[2].x, triangle[2].y, triangle[2].z);
vbo.glEnd(gl);
@@ -436,27 +445,31 @@ public class GLShapeDrawer {
}
public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) {
- ImmModeSink vbo = new ImmModeSink(gl.GL_FLOAT, gl.GL_STATIC_DRAW, 3, 0, 3, 0, 10);
+ ImmModeSink vbo = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 10,
+ 3, GL.GL_FLOAT, // vertex
+ 4, GL.GL_FLOAT, // color
+ 0, GL.GL_FLOAT, // normal
+ 0, GL.GL_FLOAT); // texture
if (wireframe) {
vbo.glBegin(gl.GL_LINES);
- vbo.glColor3f(1, 0, 0);
+ vbo.glColor4f(1, 0, 0, 1);
vbo.glVertex3f(triangle[0].x, triangle[0].y, triangle[0].z);
vbo.glVertex3f(triangle[1].x, triangle[1].y, triangle[1].z);
- vbo.glColor3f(0, 1, 0);
+ vbo.glColor4f(0, 1, 0, 1);
vbo.glVertex3f(triangle[2].x, triangle[2].y, triangle[2].z);
vbo.glVertex3f(triangle[1].x, triangle[1].y, triangle[1].z);
- vbo.glColor3f(0, 0, 1);
+ vbo.glColor4f(0, 0, 1, 1);
vbo.glVertex3f(triangle[2].x, triangle[2].y, triangle[2].z);
vbo.glVertex3f(triangle[0].x, triangle[0].y, triangle[0].z);
vbo.glEnd(gl);
}
else {
vbo.glBegin(gl.GL_TRIANGLES);
- vbo.glColor3f(1, 0, 0);
+ vbo.glColor4f(1, 0, 0, 1);
vbo.glVertex3f(triangle[0].x, triangle[0].y, triangle[0].z);
- vbo.glColor3f(0, 1, 0);
+ vbo.glColor4f(0, 1, 0, 1);
vbo.glVertex3f(triangle[1].x, triangle[1].y, triangle[1].z);
- vbo.glColor3f(0, 0, 1);
+ vbo.glColor4f(0, 0, 1, 1);
vbo.glVertex3f(triangle[2].x, triangle[2].y, triangle[2].z);
vbo.glEnd(gl);
}
@@ -471,15 +484,19 @@ public class GLShapeDrawer {
}
public void internalProcessTriangleIndex(Vector3f[] triangle, int partId, int triangleIndex) {
- ImmModeSink vbo = new ImmModeSink(gl.GL_FLOAT, gl.GL_STATIC_DRAW, 3, 0, 3, 0, 10);
+ ImmModeSink vbo = ImmModeSink.createFixed(GL.GL_STATIC_DRAW, 10,
+ 3, GL.GL_FLOAT, // vertex
+ 4, GL.GL_FLOAT, // color
+ 0, GL.GL_FLOAT, // normal
+ 0, GL.GL_FLOAT); // texture
vbo.glBegin(gl.GL_TRIANGLES);//LINES);
- vbo.glColor3f(1, 0, 0);
+ vbo.glColor4f(1, 0, 0, 1);
vbo.glVertex3f(triangle[0].x, triangle[0].y, triangle[0].z);
vbo.glVertex3f(triangle[1].x, triangle[1].y, triangle[1].z);
- vbo.glColor3f(0, 1, 0);
+ vbo.glColor4f(0, 1, 0, 1);
vbo.glVertex3f(triangle[2].x, triangle[2].y, triangle[2].z);
vbo.glVertex3f(triangle[1].x, triangle[1].y, triangle[1].z);
- vbo.glColor3f(0, 0, 1);
+ vbo.glColor4f(0, 0, 1, 1);
vbo.glVertex3f(triangle[2].x, triangle[2].y, triangle[2].z);
vbo.glVertex3f(triangle[0].x, triangle[0].y, triangle[0].z);
vbo.glEnd(gl);