diff options
Diffstat (limited to 'src/demos/es1')
-rwxr-xr-x | src/demos/es1/RedSquare.java | 39 | ||||
-rwxr-xr-x | src/demos/es1/angeles/AngelesES1.java | 2 | ||||
-rwxr-xr-x | src/demos/es1/angeles/AngelesGL.java | 107 | ||||
-rwxr-xr-x | src/demos/es1/angeles/AngelesGLil.java | 118 | ||||
-rw-r--r-- | src/demos/es1/cube/Cube.java | 46 | ||||
-rw-r--r-- | src/demos/es1/cube/CubeImmModeSink.java | 56 | ||||
-rwxr-xr-x | src/demos/es1/cubefbo/FBCubes.java | 25 |
7 files changed, 236 insertions, 157 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index f0aa540..04ea334 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -2,8 +2,11 @@ package demos.es1; import java.nio.*; import javax.media.opengl.*; +import javax.media.opengl.sub.fixed.*; import javax.media.opengl.util.*; import javax.media.opengl.glu.*; +import com.sun.opengl.util.glsl.fixed.*; +import com.sun.opengl.impl.fixed.GLFixedFuncImpl; import com.sun.javafx.newt.*; @@ -93,8 +96,21 @@ public class RedSquare implements MouseListener, GLEventListener { private FloatBuffer vertices; public void init(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - glu = GLU.createGLU(); + GLFixedFuncIf gl; + { + GL _gl = drawable.getGL(); + if(!GLFixedFuncUtil.isGLFixedFuncIf(_gl)) { + if(_gl.isGLES2()) { + gl = new GLFixedFuncImpl(_gl, new FixedFuncHook(_gl.getGL2ES2())); + } else { + gl = new GLFixedFuncImpl(_gl, _gl.getGL2ES1()); + } + _gl.getContext().setGL(gl); + } else { + gl = GLFixedFuncUtil.getGLFixedFuncIf(_gl); + } + } + System.err.println("Entering initialization"); System.err.println("GL Profile: "+GLProfile.getProfile()); System.err.println("GL:" + gl); @@ -102,10 +118,7 @@ public class RedSquare implements MouseListener, GLEventListener { System.err.println("GL_EXTENSIONS:"); System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); - if(gl.isGLES2()) { - gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE); - System.err.println("RedSquare Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE"); - } + glu = GLU.createGLU(); // Allocate vertex arrays colors = BufferUtil.newFloatBuffer(16); @@ -122,16 +135,16 @@ public class RedSquare implements MouseListener, GLEventListener { 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); + 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(gl.GL_DEPTH_TEST); + gl.glEnable(GL.GL_DEPTH_TEST); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - GL gl = drawable.getGL(); + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); // Set location in front of camera gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); @@ -141,8 +154,8 @@ public class RedSquare implements MouseListener, GLEventListener { } public void display(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // One rotation every four seconds gl.glMatrixMode(gl.GL_MODELVIEW); @@ -154,7 +167,7 @@ public class RedSquare implements MouseListener, GLEventListener { // Draw a square - gl.glDrawArrays(gl.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/angeles/AngelesES1.java b/src/demos/es1/angeles/AngelesES1.java index 8638317..28369e2 100755 --- a/src/demos/es1/angeles/AngelesES1.java +++ b/src/demos/es1/angeles/AngelesES1.java @@ -125,7 +125,7 @@ public class AngelesES1 implements GLEventListener { gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST); - //gl.glShadeModel(GL.GL_SMOOTH); + //gl.glShadeModel(GL2ES1.GL_SMOOTH); gl.glShadeModel(gl.GL_FLAT); gl.glDisable(gl.GL_DITHER); diff --git a/src/demos/es1/angeles/AngelesGL.java b/src/demos/es1/angeles/AngelesGL.java index bb2aecd..7df2526 100755 --- a/src/demos/es1/angeles/AngelesGL.java +++ b/src/demos/es1/angeles/AngelesGL.java @@ -25,8 +25,12 @@ package demos.es1.angeles; import javax.media.opengl.*; +import javax.media.opengl.sub.*; +import javax.media.opengl.sub.fixed.*; import javax.media.opengl.util.*; import javax.media.opengl.glu.*; +import com.sun.opengl.util.glsl.fixed.*; +import com.sun.opengl.impl.fixed.GLFixedFuncImpl; import java.nio.*; public class AngelesGL implements GLEventListener { @@ -79,17 +83,26 @@ public class AngelesGL implements GLEventListener { public void init(GLAutoDrawable drawable) { // FIXME: gl.setSwapInterval(1); - this.gl = drawable.getGL(); - this.glu = GLU.createGLU(); - if(gl.isGLES2()) { - gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE); - System.err.println("AngelesGL Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE"); + { + GL _gl = drawable.getGL(); + if(!GLFixedFuncUtil.isGLFixedFuncIf(_gl)) { + if(_gl.isGLES2()) { + this.gl = new GLFixedFuncImpl(_gl, new FixedFuncHook(_gl.getGL2ES2())); + } else { + this.gl = new GLFixedFuncImpl(_gl, _gl.getGL2ES1()); + } + _gl.getContext().setGL(this.gl); + } else { + this.gl = GLFixedFuncUtil.getGLFixedFuncIf(_gl); + } + System.err.println("AngelesGL: "+this.gl); } + this.glu = GLU.createGLU(); cComps = gl.isGLES1() ? 4: 3; gl.glEnable(GL2ES1.GL_NORMALIZE); - gl.glEnable(gl.GL_DEPTH_TEST); - gl.glDisable(gl.GL_CULL_FACE); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glDisable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_BACK); gl.glShadeModel(gl.GL_FLAT); @@ -135,7 +148,7 @@ public class AngelesGL implements GLEventListener { this.x = x; this.y = y; - this.gl = drawable.getGL(); + this.gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); @@ -144,9 +157,9 @@ public class AngelesGL implements GLEventListener { // JAU gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST); - //gl.glShadeModel(GL.GL_SMOOTH); + //gl.glShadeModel(gl.GL_SMOOTH); gl.glShadeModel(gl.GL_FLAT); - gl.glDisable(gl.GL_DITHER); + gl.glDisable(GL.GL_DITHER); //gl.glMatrixMode(gl.GL_PROJECTION); //gl.glLoadIdentity(); @@ -161,7 +174,7 @@ public class AngelesGL implements GLEventListener { if (gAppAlive==0) return; - this.gl = drawable.getGL(); + this.gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); // Actual tick value is "blurred" a little bit. sTick = (sTick + tick - sStartTick) >> 1; @@ -173,7 +186,7 @@ public class AngelesGL implements GLEventListener { return; } - gl.glClear(gl.GL_DEPTH_BUFFER_BIT | gl.GL_COLOR_BUFFER_BIT); + gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); @@ -186,7 +199,7 @@ public class AngelesGL implements GLEventListener { configureLightAndMaterial(); if(blendingEnabled) { - gl.glEnable(gl.GL_CULL_FACE); + gl.glEnable(GL.GL_CULL_FACE); // Draw the reflection by drawing models with negated Z-axis. gl.glPushMatrix(); drawModels(-1); @@ -197,7 +210,7 @@ public class AngelesGL implements GLEventListener { drawGroundPlane(); if(blendingEnabled) { - gl.glDisable(gl.GL_CULL_FACE); + gl.glDisable(GL.GL_CULL_FACE); } // Draw all the models normally. @@ -216,7 +229,7 @@ public class AngelesGL implements GLEventListener { } private boolean blendingEnabled = true; - private GL gl; + private GLFixedFuncIf gl; // temp cache private GLU glu; // Total run length is 20 * camera track base unit length (see cams.h). @@ -239,16 +252,16 @@ int randomUInt() private int cComps; // Definition of one GL object in this demo. -public class GLObject { +public class GLSpatial { /* Vertex array and color array are enabled for all objects, so their * pointers must always be valid and non-null. Normal array is not * used by the ground plane, so when its pointer is null then normal * array usage is disabled. * - * Vertex array is supposed to use gl.GL_FLOAT datatype and stride 0 + * Vertex array is supposed to use GL.GL_FLOAT datatype and stride 0 * (i.e. tightly packed array). Color array is supposed to have 4 - * components per color with gl.GL_UNSIGNED_BYTE datatype and stride 0. - * Normal array is supposed to use gl.GL_FLOAT datatype and stride 0. + * components per color with GL.GL_UNSIGNED_BYTE datatype and stride 0. + * Normal array is supposed to use GL.GL_FLOAT datatype and stride 0. */ private int vboName, count; private int vComps, nComps; @@ -258,7 +271,7 @@ public class GLObject { private FloatBuffer normalArray=null; protected GLArrayDataWrapper vArrayData, cArrayData, nArrayData=null; - public GLObject(int vertices, int vertexComponents, + public GLSpatial(int vertices, int vertexComponents, boolean useNormalArray) { count = vertices; vComps= vertexComponents; @@ -292,12 +305,12 @@ public class GLObject { gl.glGenBuffers(1, tmp, 0); vboName = tmp[0]; - vArrayData = GLArrayDataWrapper.createFixed(GL.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, + vArrayData = GLArrayDataWrapper.createFixed(gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, 0, pBuffer, vboName, vOffset); - cArrayData = GLArrayDataWrapper.createFixed(GL.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, + cArrayData = GLArrayDataWrapper.createFixed(gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, 0, pBuffer, vboName, cOffset); if(useNormalArray) { - nArrayData = GLArrayDataWrapper.createFixed(GL.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, + nArrayData = GLArrayDataWrapper.createFixed(gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, 0, pBuffer, vboName, nOffset); } } @@ -354,7 +367,7 @@ public class GLObject { } - gl.glDrawArrays(gl.GL_TRIANGLES, 0, count); + gl.glDrawArrays(GL.GL_TRIANGLES, 0, count); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); @@ -371,8 +384,8 @@ int sCurrentCamTrack = 0; long sCurrentCamTrackStartTick = 0; long sNextCamTrackStartTick = 0x7fffffff; -GLObject sSuperShapeObjects[] = new GLObject[SuperShape.COUNT]; -GLObject sGroundPlane; +GLSpatial sSuperShapeObjects[] = new GLSpatial[SuperShape.COUNT]; +GLSpatial sGroundPlane; public class VECTOR3 { @@ -422,7 +435,7 @@ float ssFunc(final float t, final float p[], int pOff) // Creates and returns a supershape object. // Based on Paul Bourke's POV-Ray implementation. // http://astronomy.swin.edu.au/~pbourke/povray/supershape/ -GLObject createSuperShape(final float params[]) +GLSpatial createSuperShape(final float params[]) { final int resol1 = (int)params[SuperShape.PARAMS - 3]; final int resol2 = (int)params[SuperShape.PARAMS - 2]; @@ -434,12 +447,12 @@ GLObject createSuperShape(final float params[]) final int latitudeCount = latitudeEnd - latitudeBegin; final int triangleCount = longitudeCount * latitudeCount * 2; final int vertices = triangleCount * 3; - GLObject result; + GLSpatial result; float baseColor[] = new float[3]; int a, longitude, latitude; int currentVertex, currentQuad; - result = new GLObject(vertices, 3, true); + result = new GLSpatial(vertices, 3, true); if (result == null) return null; @@ -499,7 +512,7 @@ GLObject createSuperShape(final float params[]) /* Pre-normalization of the normals is disabled here because * they will be normalized anyway later due to automatic - * normalization (gl.GL_NORMALIZE). It is enabled because the + * normalization (GL2ES1.GL_NORMALIZE). It is enabled because the * objects are scaled with glScale. */ /* @@ -576,19 +589,19 @@ GLObject createSuperShape(final float params[]) } -GLObject createGroundPlane() +GLSpatial createGroundPlane() { final int scale = 4; final int yBegin = -15, yEnd = 15; // ends are non-inclusive final int xBegin = -15, xEnd = 15; final int triangleCount = (yEnd - yBegin) * (xEnd - xBegin) * 2; final int vertices = triangleCount * 3; - GLObject result; + GLSpatial result; int x, y; int currentVertex, currentQuad; final int vcomps = 2; - result = new GLObject(vertices, vcomps, false); + result = new GLSpatial(vertices, vcomps, false); if (result == null) return null; @@ -638,18 +651,18 @@ GLObject createGroundPlane() void drawGroundPlane() { gl.glDisable(gl.GL_LIGHTING); - gl.glDisable(gl.GL_DEPTH_TEST); + gl.glDisable(GL.GL_DEPTH_TEST); if(blendingEnabled) { - gl.glEnable(gl.GL_BLEND); - gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR); + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR); } sGroundPlane.draw(); if(blendingEnabled) { - gl.glDisable(gl.GL_BLEND); + gl.glDisable(GL.GL_BLEND); } - gl.glEnable(gl.GL_DEPTH_TEST); + gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(gl.GL_LIGHTING); } @@ -664,9 +677,9 @@ void drawFadeQuad() final float fadeColor = FixedPoint.toFloat(minFade << 7); gl.glColor4f(fadeColor, fadeColor, fadeColor, 0f); - gl.glDisable(gl.GL_DEPTH_TEST); - gl.glEnable(gl.GL_BLEND); - gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR); + gl.glDisable(GL.GL_DEPTH_TEST); + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR); gl.glDisable(gl.GL_LIGHTING); gl.glMatrixMode(gl.GL_MODELVIEW); @@ -679,15 +692,15 @@ void drawFadeQuad() gl.glDisableClientState(gl.GL_COLOR_ARRAY); gl.glDisableClientState(gl.GL_NORMAL_ARRAY); gl.glEnableClientState(gl.GL_VERTEX_ARRAY); - gl.glVertexPointer(2, gl.GL_FLOAT, 0, quadVertices); - gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6); + gl.glVertexPointer(2, GL.GL_FLOAT, 0, quadVertices); + gl.glDrawArrays(GL.GL_TRIANGLES, 0, 6); gl.glEnableClientState(gl.GL_COLOR_ARRAY); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glEnable(gl.GL_LIGHTING); - gl.glDisable(gl.GL_BLEND); - gl.glEnable(gl.GL_DEPTH_TEST); + gl.glDisable(GL.GL_BLEND); + gl.glEnable(GL.GL_DEPTH_TEST); } } @@ -708,9 +721,9 @@ void configureLightAndMaterial() gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light1Diffuse); gl.glLightfv(gl.GL_LIGHT2, gl.GL_POSITION, light2Position); gl.glLightfv(gl.GL_LIGHT2, gl.GL_DIFFUSE, light2Diffuse); - gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular); + gl.glMaterialfv(GL.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular); - gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60.0f); + gl.glMaterialf(GL.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60.0f); gl.glEnable(gl.GL_COLOR_MATERIAL); } diff --git a/src/demos/es1/angeles/AngelesGLil.java b/src/demos/es1/angeles/AngelesGLil.java index ace1a4f..8e71840 100755 --- a/src/demos/es1/angeles/AngelesGLil.java +++ b/src/demos/es1/angeles/AngelesGLil.java @@ -25,8 +25,12 @@ package demos.es1.angeles; import javax.media.opengl.*; +import javax.media.opengl.sub.*; +import javax.media.opengl.sub.fixed.*; import javax.media.opengl.util.*; import javax.media.opengl.glu.*; +import com.sun.opengl.util.glsl.fixed.*; +import com.sun.opengl.impl.fixed.GLFixedFuncImpl; import java.nio.*; public class AngelesGLil implements GLEventListener { @@ -79,25 +83,33 @@ public class AngelesGLil implements GLEventListener { public void init(GLAutoDrawable drawable) { // FIXME: gl.setSwapInterval(1); - this.gl = drawable.getGL(); - this.glu = GLU.createGLU(); - if(gl.isGLES2()) { - gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE); - System.err.println("AngelesGLil Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE"); + { + GL _gl = drawable.getGL(); + if(!GLFixedFuncUtil.isGLFixedFuncIf(_gl)) { + if(_gl.isGLES2()) { + this.gl = new GLFixedFuncImpl(_gl, new FixedFuncHook(_gl.getGL2ES2())); + } else { + this.gl = new GLFixedFuncImpl(_gl, _gl.getGL2ES1()); + } + _gl.getContext().setGL(this.gl); + } else { + this.gl = GLFixedFuncUtil.getGLFixedFuncIf(_gl); + } + System.err.println("AngelesGL: "+this.gl); } - + this.glu = GLU.createGLU(); cComps = gl.isGLES1() ? 4: 3; gl.glEnable(GL2ES1.GL_NORMALIZE); - gl.glEnable(gl.GL_DEPTH_TEST); - gl.glDisable(gl.GL_CULL_FACE); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glDisable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_BACK); gl.glShadeModel(gl.GL_FLAT); gl.glEnable(gl.GL_LIGHTING); gl.glEnable(gl.GL_LIGHT0); gl.glEnable(gl.GL_LIGHT1); - gl.glEnable(gl.GL_LIGHT2); + gl.glEnable(gl.GL_LIGHT2); gl.glEnableClientState(gl.GL_VERTEX_ARRAY); gl.glEnableClientState(gl.GL_COLOR_ARRAY); @@ -139,7 +151,7 @@ public class AngelesGLil implements GLEventListener { TraceGL2 gltrace = new TraceGL2(gl2, System.err); gl2.getContext().setGL(gltrace); gl2 = gltrace; - }*/ + } */ } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { @@ -148,7 +160,7 @@ public class AngelesGLil implements GLEventListener { this.x = x; this.y = y; - this.gl = drawable.getGL(); + this.gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); @@ -157,9 +169,9 @@ public class AngelesGLil implements GLEventListener { // JAU gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST); - //gl.glShadeModel(GL.GL_SMOOTH); + //gl.glShadeModel(gl.GL_SMOOTH); gl.glShadeModel(gl.GL_FLAT); - gl.glDisable(gl.GL_DITHER); + gl.glDisable(GL.GL_DITHER); //gl.glMatrixMode(gl.GL_PROJECTION); //gl.glLoadIdentity(); @@ -174,7 +186,7 @@ public class AngelesGLil implements GLEventListener { if (gAppAlive==0) return; - this.gl = drawable.getGL(); + this.gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); // Actual tick value is "blurred" a little bit. sTick = (sTick + tick - sStartTick) >> 1; @@ -186,7 +198,7 @@ public class AngelesGLil implements GLEventListener { return; } - gl.glClear(gl.GL_DEPTH_BUFFER_BIT | gl.GL_COLOR_BUFFER_BIT); + gl.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); @@ -199,7 +211,7 @@ public class AngelesGLil implements GLEventListener { configureLightAndMaterial(); if(blendingEnabled) { - gl.glEnable(gl.GL_CULL_FACE); + gl.glEnable(GL.GL_CULL_FACE); // Draw the reflection by drawing models with negated Z-axis. gl.glPushMatrix(); drawModels(-1); @@ -210,7 +222,7 @@ public class AngelesGLil implements GLEventListener { drawGroundPlane(); if(blendingEnabled) { - gl.glDisable(gl.GL_CULL_FACE); + gl.glDisable(GL.GL_CULL_FACE); } // Draw all the models normally. @@ -229,7 +241,7 @@ public class AngelesGLil implements GLEventListener { } private boolean blendingEnabled = true; - private GL gl; + private GLFixedFuncIf gl; // temp cache private GLU glu; // Total run length is 20 * camera track base unit length (see cams.h). @@ -249,20 +261,19 @@ int randomUInt() return Math.abs((int) (sRandomSeed >> 16)); } - private int cComps; // Definition of one GL object in this demo. -public class GLObject { +public class GLSpatial { /* Vertex array and color array are enabled for all objects, so their * pointers must always be valid and non-null. Normal array is not * used by the ground plane, so when its pointer is null then normal * array usage is disabled. * - * Vertex array is supposed to use gl.GL_FLOAT datatype and stride 0 + * Vertex array is supposed to use GL.GL_FLOAT datatype and stride 0 * (i.e. tightly packed array). Color array is supposed to have 4 - * components per color with gl.GL_UNSIGNED_BYTE datatype and stride 0. - * Normal array is supposed to use gl.GL_FLOAT datatype and stride 0. + * components per color with GL.GL_UNSIGNED_BYTE datatype and stride 0. + * Normal array is supposed to use GL.GL_FLOAT datatype and stride 0. */ protected int vboName, count; protected int vComps, nComps; @@ -270,7 +281,7 @@ public class GLObject { protected FloatBuffer interlArray; protected GLArrayDataWrapper vArrayData, cArrayData, nArrayData=null; - public GLObject(int vertices, int vertexComponents, + public GLSpatial(int vertices, int vertexComponents, boolean useNormalArray) { count = vertices; vComps= vertexComponents; @@ -297,12 +308,12 @@ public class GLObject { interlArray.position(count*(vComps+cComps+nComps)); interlArray.flip(); - vArrayData = GLArrayDataWrapper.createFixed(GL.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, + vArrayData = GLArrayDataWrapper.createFixed(gl.GL_VERTEX_ARRAY, vComps, GL.GL_FLOAT, false, bStride, pBuffer, vboName, vOffset); - cArrayData = GLArrayDataWrapper.createFixed(GL.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, + cArrayData = GLArrayDataWrapper.createFixed(gl.GL_COLOR_ARRAY, cComps, GL.GL_FLOAT, false, bStride, pBuffer, vboName, cOffset); if(useNormalArray) { - nArrayData = GLArrayDataWrapper.createFixed(GL.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, + nArrayData = GLArrayDataWrapper.createFixed(gl.GL_NORMAL_ARRAY, nComps, GL.GL_FLOAT, false, bStride, pBuffer, vboName, nOffset); } } @@ -342,7 +353,8 @@ public class GLObject { gl.glNormalPointer(nArrayData); } - gl.glDrawArrays(gl.GL_TRIANGLES, 0, count); + + gl.glDrawArrays(GL.GL_TRIANGLES, 0, count); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); @@ -359,8 +371,8 @@ int sCurrentCamTrack = 0; long sCurrentCamTrackStartTick = 0; long sNextCamTrackStartTick = 0x7fffffff; -GLObject sSuperShapeObjects[] = new GLObject[SuperShape.COUNT]; -GLObject sGroundPlane; +GLSpatial sSuperShapeObjects[] = new GLSpatial[SuperShape.COUNT]; +GLSpatial sGroundPlane; public class VECTOR3 { @@ -410,7 +422,7 @@ float ssFunc(final float t, final float p[], int pOff) // Creates and returns a supershape object. // Based on Paul Bourke's POV-Ray implementation. // http://astronomy.swin.edu.au/~pbourke/povray/supershape/ -GLObject createSuperShape(final float params[]) +GLSpatial createSuperShape(final float params[]) { final int resol1 = (int)params[SuperShape.PARAMS - 3]; final int resol2 = (int)params[SuperShape.PARAMS - 2]; @@ -422,19 +434,18 @@ GLObject createSuperShape(final float params[]) final int latitudeCount = latitudeEnd - latitudeBegin; final int triangleCount = longitudeCount * latitudeCount * 2; final int vertices = triangleCount * 3; - GLObject result; + GLSpatial result; float baseColor[] = new float[3]; float color[] = new float[3]; int a, longitude, latitude; int currentIndex, currentQuad; - result = new GLObject(vertices, 3, true); + result = new GLSpatial(vertices, 3, true); if (result == null) return null; - for (a = 0; a < 3; ++a) { + for (a = 0; a < 3; ++a) baseColor[a] = ((randomUInt() % 155) + 100) / 255.f; - } currentQuad = 0; currentIndex = 0; @@ -489,7 +500,7 @@ GLObject createSuperShape(final float params[]) /* Pre-normalization of the normals is disabled here because * they will be normalized anyway later due to automatic - * normalization (gl.GL_NORMALIZE). It is enabled because the + * normalization (GL2ES1.GL_NORMALIZE). It is enabled because the * objects are scaled with glScale. */ /* @@ -607,19 +618,20 @@ GLObject createSuperShape(final float params[]) return result; } -GLObject createGroundPlane() + +GLSpatial createGroundPlane() { final int scale = 4; final int yBegin = -15, yEnd = 15; // ends are non-inclusive final int xBegin = -15, xEnd = 15; final int triangleCount = (yEnd - yBegin) * (xEnd - xBegin) * 2; final int vertices = triangleCount * 3; - GLObject result; + GLSpatial result; int x, y; int currentIndex, currentQuad; final int vcomps = 2; - result = new GLObject(vertices, vcomps, false); + result = new GLSpatial(vertices, vcomps, false); if (result == null) return null; @@ -665,18 +677,18 @@ GLObject createGroundPlane() void drawGroundPlane() { gl.glDisable(gl.GL_LIGHTING); - gl.glDisable(gl.GL_DEPTH_TEST); + gl.glDisable(GL.GL_DEPTH_TEST); if(blendingEnabled) { - gl.glEnable(gl.GL_BLEND); - gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR); + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR); } sGroundPlane.draw(); if(blendingEnabled) { - gl.glDisable(gl.GL_BLEND); + gl.glDisable(GL.GL_BLEND); } - gl.glEnable(gl.GL_DEPTH_TEST); + gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(gl.GL_LIGHTING); } @@ -691,9 +703,9 @@ void drawFadeQuad() final float fadeColor = FixedPoint.toFloat(minFade << 7); gl.glColor4f(fadeColor, fadeColor, fadeColor, 0f); - gl.glDisable(gl.GL_DEPTH_TEST); - gl.glEnable(gl.GL_BLEND); - gl.glBlendFunc(gl.GL_ZERO, gl.GL_SRC_COLOR); + gl.glDisable(GL.GL_DEPTH_TEST); + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_ZERO, GL.GL_SRC_COLOR); gl.glDisable(gl.GL_LIGHTING); gl.glMatrixMode(gl.GL_MODELVIEW); @@ -706,15 +718,15 @@ void drawFadeQuad() gl.glDisableClientState(gl.GL_COLOR_ARRAY); gl.glDisableClientState(gl.GL_NORMAL_ARRAY); gl.glEnableClientState(gl.GL_VERTEX_ARRAY); - gl.glVertexPointer(2, gl.GL_FLOAT, 0, quadVertices); - gl.glDrawArrays(gl.GL_TRIANGLES, 0, 6); + gl.glVertexPointer(2, GL.GL_FLOAT, 0, quadVertices); + gl.glDrawArrays(GL.GL_TRIANGLES, 0, 6); gl.glEnableClientState(gl.GL_COLOR_ARRAY); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glEnable(gl.GL_LIGHTING); - gl.glDisable(gl.GL_BLEND); - gl.glEnable(gl.GL_DEPTH_TEST); + gl.glDisable(GL.GL_BLEND); + gl.glEnable(GL.GL_DEPTH_TEST); } } @@ -735,9 +747,9 @@ void configureLightAndMaterial() gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, light1Diffuse); gl.glLightfv(gl.GL_LIGHT2, gl.GL_POSITION, light2Position); gl.glLightfv(gl.GL_LIGHT2, gl.GL_DIFFUSE, light2Diffuse); - gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular); + gl.glMaterialfv(GL.GL_FRONT_AND_BACK, gl.GL_SPECULAR, materialSpecular); - gl.glMaterialf(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60.0f); + gl.glMaterialf(GL.GL_FRONT_AND_BACK, gl.GL_SHININESS, 60.0f); gl.glEnable(gl.GL_COLOR_MATERIAL); } diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java index b77c4e9..63bea14 100644 --- a/src/demos/es1/cube/Cube.java +++ b/src/demos/es1/cube/Cube.java @@ -31,10 +31,13 @@ */ package demos.es1.cube; +import java.nio.*; import javax.media.opengl.*; +import javax.media.opengl.sub.fixed.*; import javax.media.opengl.util.*; import javax.media.opengl.glu.*; -import java.nio.*; +import com.sun.opengl.util.glsl.fixed.*; +import com.sun.opengl.impl.fixed.GLFixedFuncImpl; import com.sun.javafx.newt.*; @@ -71,13 +74,23 @@ public class Cube implements GLEventListener { } 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("Cubes Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE"); + GLFixedFuncIf gl; + { + GL _gl = drawable.getGL(); + if(!GLFixedFuncUtil.isGLFixedFuncIf(_gl)) { + if(_gl.isGLES2()) { + gl = new GLFixedFuncImpl(_gl, new FixedFuncHook(_gl.getGL2ES2())); + } else { + gl = new GLFixedFuncImpl(_gl, _gl.getGL2ES1()); + } + _gl.getContext().setGL(gl); + } else { + gl = GLFixedFuncUtil.getGLFixedFuncIf(_gl); + } } + glu = GLU.createGLU(); + gl.glGenBuffers(4, vboNames, 0); if(!innerCube) { @@ -87,16 +100,17 @@ public class Cube implements GLEventListener { System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); System.err.println("GL_EXTENSIONS:"); System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); + System.err.println("GLF:" + gl); } } 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; + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); + GL2ES1 gl2es1=null; if(gl.isGL2ES1()) { - glF = drawable.getGL().getGL2ES1(); + gl2es1 = drawable.getGL().getGL2ES1(); } gl.glViewport(0, 0, width, height); @@ -128,11 +142,11 @@ public class Cube implements GLEventListener { gl.glDisable(gl.GL_LIGHT0); } gl.glEnable(gl.GL_CULL_FACE); - if(null!=glF) { + if(null!=gl2es1) { gl.glEnable(gl.GL_NORMALIZE); gl.glShadeModel(gl.GL_SMOOTH); - gl.glDisable(gl.GL_DITHER); + gl.glDisable(GL.GL_DITHER); } gl.glEnableClientState(gl.GL_VERTEX_ARRAY); @@ -155,16 +169,16 @@ public class Cube implements GLEventListener { gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[3]); gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeTexCoords.limit() * BufferUtil.SIZEOF_SHORT, cubeTexCoords, GL.GL_STATIC_DRAW); gl.glTexCoordPointer(2, gl.GL_SHORT, 0, 0); - if(null!=glF) { - glF.glTexEnvi(glF.GL_TEXTURE_ENV, glF.GL_TEXTURE_ENV_MODE, glF.GL_INCR); + if(null!=gl2es1) { + gl2es1.glTexEnvi(gl2es1.GL_TEXTURE_ENV, gl2es1.GL_TEXTURE_ENV_MODE, gl2es1.GL_INCR); } } else { gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); } gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); - if(null!=glF) { - glF.glHint(glF.GL_PERSPECTIVE_CORRECTION_HINT, glF.GL_FASTEST); + if(null!=gl2es1) { + gl2es1.glHint(gl2es1.GL_PERSPECTIVE_CORRECTION_HINT, gl2es1.GL_FASTEST); } gl.glMatrixMode(gl.GL_PROJECTION); @@ -179,7 +193,7 @@ public class Cube implements GLEventListener { } public void display(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); diff --git a/src/demos/es1/cube/CubeImmModeSink.java b/src/demos/es1/cube/CubeImmModeSink.java index a3f1570..c85fed0 100644 --- a/src/demos/es1/cube/CubeImmModeSink.java +++ b/src/demos/es1/cube/CubeImmModeSink.java @@ -32,8 +32,11 @@ package demos.es1.cube; import javax.media.opengl.*; +import javax.media.opengl.sub.fixed.*; import javax.media.opengl.util.*; import javax.media.opengl.glu.*; +import com.sun.opengl.util.glsl.fixed.*; +import com.sun.opengl.impl.fixed.GLFixedFuncImpl; import java.nio.*; import com.sun.javafx.newt.*; @@ -47,7 +50,7 @@ public class CubeImmModeSink implements GLEventListener { ByteBuffer cubeIndices=null; ImmModeSink vboCubeF = null; - public void drawCube(GL gl, float extent) { + public void drawCube(GLFixedFuncIf gl, float extent) { if(cubeIndices==null) { cubeIndices = BufferUtil.newByteBuffer(s_cubeIndices); } @@ -83,7 +86,7 @@ public class CubeImmModeSink implements GLEventListener { private GLUquadric sphere=null; private ImmModeSink vboSphere=null; - public void drawSphere(GL gl, float radius, int slices, int stacks) { + public void drawSphere(GLFixedFuncIf gl, float radius, int slices, int stacks) { if(sphere==null) { sphere = glu.gluNewQuadric(); sphere.enableImmModeSink(true); @@ -108,7 +111,7 @@ public class CubeImmModeSink implements GLEventListener { private GLUquadric cylinder=null; private ImmModeSink vboCylinder=null; - public void drawCylinder(GL gl, float radius, float halfHeight, int upAxis) { + public void drawCylinder(GLFixedFuncIf gl, float radius, float halfHeight, int upAxis) { if(cylinder==null) { cylinder = glu.gluNewQuadric(); cylinder.enableImmModeSink(true); @@ -161,13 +164,23 @@ public class CubeImmModeSink implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); + GLFixedFuncIf gl; + { + GL _gl = drawable.getGL(); + if(!GLFixedFuncUtil.isGLFixedFuncIf(_gl)) { + if(_gl.isGLES2()) { + gl = new GLFixedFuncImpl(_gl, new FixedFuncHook(_gl.getGL2ES2())); + } else { + gl = new GLFixedFuncImpl(_gl, _gl.getGL2ES1()); + } + _gl.getContext().setGL(gl); + } else { + gl = GLFixedFuncUtil.getGLFixedFuncIf(_gl); + } + } 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()); @@ -175,6 +188,7 @@ public class CubeImmModeSink implements GLEventListener { System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION)); System.err.println("GL_EXTENSIONS:"); System.err.println(" " + gl.glGetString(gl.GL_EXTENSIONS)); + System.err.println("GLF:" + gl); } gl.glGetError(); // flush error .. @@ -191,10 +205,10 @@ public class CubeImmModeSink implements GLEventListener { 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; + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); + GL2ES1 gl2es1=null; if(gl.isGL2ES1()) { - glF = drawable.getGL().getGL2ES1(); + gl2es1 = drawable.getGL().getGL2ES1(); } gl.glViewport(0, 0, width, height); @@ -215,19 +229,19 @@ public class CubeImmModeSink 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(glF.GL_FRONT_AND_BACK, glF.GL_SPECULAR, material_spec, 0); - gl.glEnable(glF.GL_NORMALIZE); + gl.glMaterialfv(GL.GL_FRONT_AND_BACK, gl.GL_SPECULAR, material_spec, 0); + gl.glEnable(gl.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.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); + if(null!=gl2es1) { + gl2es1.glHint(gl2es1.GL_PERSPECTIVE_CORRECTION_HINT, gl2es1.GL_FASTEST); } gl.glMatrixMode(gl.GL_PROJECTION); @@ -242,10 +256,10 @@ public class CubeImmModeSink implements GLEventListener { } public void display(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - GL2ES1 glF=null; + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); + GL2ES1 gl2es1=null; if(gl.isGL2ES1()) { - glF = drawable.getGL().getGL2ES1(); + gl2es1 = drawable.getGL().getGL2ES1(); } gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); @@ -265,13 +279,13 @@ public class CubeImmModeSink implements GLEventListener { } if(true) { - gl.glDisable(GL.GL_LIGHTING); + gl.glDisable(gl.GL_LIGHTING); gl.glColor4f(0f, 1f, 0f, 1f); gl.glPushMatrix(); gl.glTranslatef(15.0f, 0.0f, 0.0f); drawSphere(gl, 5.0f, 10, 10); gl.glPopMatrix(); - gl.glEnable(GL.GL_LIGHTING); + gl.glEnable(gl.GL_LIGHTING); } if(true) { diff --git a/src/demos/es1/cubefbo/FBCubes.java b/src/demos/es1/cubefbo/FBCubes.java index a97ee1c..f5f98f1 100755 --- a/src/demos/es1/cubefbo/FBCubes.java +++ b/src/demos/es1/cubefbo/FBCubes.java @@ -35,7 +35,11 @@ package demos.es1.cubefbo; import demos.es1.cube.Cube; import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.sub.fixed.*; import javax.media.opengl.util.FBObject; +import com.sun.opengl.util.glsl.fixed.*; +import com.sun.opengl.impl.fixed.GLFixedFuncImpl; import java.nio.*; class FBCubes implements GLEventListener { @@ -52,12 +56,21 @@ class FBCubes implements GLEventListener { } public void init(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); - - if(gl.isGLES2()) { - gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE); - System.err.println("FBCubes Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE"); + GLFixedFuncIf gl; + { + GL _gl = drawable.getGL(); + if(!GLFixedFuncUtil.isGLFixedFuncIf(_gl)) { + if(_gl.isGLES2()) { + gl = new GLFixedFuncImpl(_gl, new FixedFuncHook(_gl.getGL2ES2())); + } else { + gl = new GLFixedFuncImpl(_gl, _gl.getGL2ES1()); + } + _gl.getContext().setGL(gl); + } else { + gl = GLFixedFuncUtil.getGLFixedFuncIf(_gl); + } } + System.out.println(gl); gl.glGetError(); // flush error .. /* @@ -98,7 +111,7 @@ class FBCubes implements GLEventListener { } public void display(GLAutoDrawable drawable) { - GL gl = drawable.getGL(); + GLFixedFuncIf gl = GLFixedFuncUtil.getGLFixedFuncIf(drawable.getGL()); fbo1.bind(gl); cubeInner.reshape(drawable, 0, 0, FBO_SIZE, FBO_SIZE); |