diff options
Diffstat (limited to 'src/net/java/joglutils/msg')
16 files changed, 250 insertions, 227 deletions
diff --git a/src/net/java/joglutils/msg/actions/GLRenderAction.java b/src/net/java/joglutils/msg/actions/GLRenderAction.java index e17d97b..b65c515 100644 --- a/src/net/java/joglutils/msg/actions/GLRenderAction.java +++ b/src/net/java/joglutils/msg/actions/GLRenderAction.java @@ -96,31 +96,31 @@ public class GLRenderAction extends Action { private float curAspectRatio = 1.0f; private int applyDepth = 0; - private GL gl; + private GL2 gl; public void apply(Node node) { int depth = applyDepth++; try { if (depth == 0) { - gl = GLU.getCurrentGL(); + gl = GLU.getCurrentGL().getGL2(); // Applying to the root of the scene graph // Push necessary GL state // FIXME: add in additional bits as we add more capabilities - gl.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_CURRENT_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_TRANSFORM_BIT); - gl.glDisable(GL.GL_LIGHTING); - gl.glEnable(GL.GL_DEPTH_TEST); + gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_CURRENT_BIT | GL2.GL_DEPTH_BUFFER_BIT | GL2.GL_TRANSFORM_BIT); + gl.glDisable(GL2.GL_LIGHTING); + gl.glEnable(GL2.GL_DEPTH_TEST); gl.glColor4f(1, 1, 1, 1); - gl.glMatrixMode(GL.GL_TEXTURE); + gl.glMatrixMode(GL2.GL_TEXTURE); gl.glLoadIdentity(); - gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); - gl.glPushClientAttrib(GL.GL_CLIENT_VERTEX_ARRAY_BIT); - gl.glDisableClientState(GL.GL_VERTEX_ARRAY); - gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glPushClientAttrib(GL2.GL_CLIENT_VERTEX_ARRAY_BIT); + gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); + gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); // FIXME: should add in disabling of normal array // Figure out the aspect ratio of the current viewport int[] viewport = new int[4]; - gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); + gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0); curAspectRatio = (float) viewport[2] / (float) viewport[3]; } apply(table, node); @@ -135,7 +135,7 @@ public class GLRenderAction extends Action { } /** Returns the GL instance being used for rendering. */ - public GL getGL() { + public GL2 getGL() { return gl; } diff --git a/src/net/java/joglutils/msg/elements/GLBlendElement.java b/src/net/java/joglutils/msg/elements/GLBlendElement.java index 7955533..16e2266 100644 --- a/src/net/java/joglutils/msg/elements/GLBlendElement.java +++ b/src/net/java/joglutils/msg/elements/GLBlendElement.java @@ -76,41 +76,41 @@ public class GLBlendElement extends BlendElement { private static int oglBlendFunc(int func) { switch (func) { - case Blend.ZERO: return GL.GL_ZERO; - case Blend.ONE: return GL.GL_ONE; - case Blend.SRC_COLOR: return GL.GL_SRC_COLOR; - case Blend.ONE_MINUS_SRC_COLOR: return GL.GL_ONE_MINUS_SRC_COLOR; - case Blend.DST_COLOR: return GL.GL_DST_COLOR; - case Blend.ONE_MINUS_DST_COLOR: return GL.GL_ONE_MINUS_DST_COLOR; - case Blend.SRC_ALPHA: return GL.GL_SRC_ALPHA; - case Blend.ONE_MINUS_SRC_ALPHA: return GL.GL_ONE_MINUS_SRC_ALPHA; - case Blend.DST_ALPHA: return GL.GL_DST_ALPHA; - case Blend.ONE_MINUS_DST_ALPHA: return GL.GL_ONE_MINUS_DST_ALPHA; - case Blend.SRC_ALPHA_SATURATE: return GL.GL_SRC_ALPHA_SATURATE; - case Blend.CONSTANT_COLOR: return GL.GL_CONSTANT_COLOR; - case Blend.ONE_MINUS_CONSTANT_COLOR: return GL.GL_ONE_MINUS_CONSTANT_COLOR; - case Blend.CONSTANT_ALPHA: return GL.GL_CONSTANT_ALPHA; - case Blend.ONE_MINUS_CONSTANT_ALPHA: return GL.GL_ONE_MINUS_CONSTANT_ALPHA; + case Blend.ZERO: return GL2.GL_ZERO; + case Blend.ONE: return GL2.GL_ONE; + case Blend.SRC_COLOR: return GL2.GL_SRC_COLOR; + case Blend.ONE_MINUS_SRC_COLOR: return GL2.GL_ONE_MINUS_SRC_COLOR; + case Blend.DST_COLOR: return GL2.GL_DST_COLOR; + case Blend.ONE_MINUS_DST_COLOR: return GL2.GL_ONE_MINUS_DST_COLOR; + case Blend.SRC_ALPHA: return GL2.GL_SRC_ALPHA; + case Blend.ONE_MINUS_SRC_ALPHA: return GL2.GL_ONE_MINUS_SRC_ALPHA; + case Blend.DST_ALPHA: return GL2.GL_DST_ALPHA; + case Blend.ONE_MINUS_DST_ALPHA: return GL2.GL_ONE_MINUS_DST_ALPHA; + case Blend.SRC_ALPHA_SATURATE: return GL2.GL_SRC_ALPHA_SATURATE; + case Blend.CONSTANT_COLOR: return GL2.GL_CONSTANT_COLOR; + case Blend.ONE_MINUS_CONSTANT_COLOR: return GL2.GL_ONE_MINUS_CONSTANT_COLOR; + case Blend.CONSTANT_ALPHA: return GL2.GL_CONSTANT_ALPHA; + case Blend.ONE_MINUS_CONSTANT_ALPHA: return GL2.GL_ONE_MINUS_CONSTANT_ALPHA; } throw new InternalError("Illegal blend function " + func); } private int oglBlendEquation(int equation) { switch (equation) { - case Blend.FUNC_ADD: return GL.GL_FUNC_ADD; - case Blend.FUNC_SUBTRACT: return GL.GL_FUNC_SUBTRACT; - case Blend.FUNC_REVERSE_SUBTRACT: return GL.GL_FUNC_REVERSE_SUBTRACT; - case Blend.MIN: return GL.GL_MIN; - case Blend.MAX: return GL.GL_MAX; + case Blend.FUNC_ADD: return GL2.GL_FUNC_ADD; + case Blend.FUNC_SUBTRACT: return GL2.GL_FUNC_SUBTRACT; + case Blend.FUNC_REVERSE_SUBTRACT: return GL2.GL_FUNC_REVERSE_SUBTRACT; + case Blend.MIN: return GL2.GL_MIN; + case Blend.MAX: return GL2.GL_MAX; } throw new InternalError("Illegal blend equation " + equation); } - private static void validateFunc(GL gl, int func) { - if (func == GL.GL_CONSTANT_COLOR || - func == GL.GL_ONE_MINUS_CONSTANT_COLOR || - func == GL.GL_CONSTANT_ALPHA || - func == GL.GL_ONE_MINUS_CONSTANT_ALPHA) { + private static void validateFunc(GL2 gl, int func) { + if (func == GL2.GL_CONSTANT_COLOR || + func == GL2.GL_ONE_MINUS_CONSTANT_COLOR || + func == GL2.GL_CONSTANT_ALPHA || + func == GL2.GL_ONE_MINUS_CONSTANT_ALPHA) { if (!gl.isExtensionAvailable("GL_ARB_imaging")) { throw new RuntimeException("Blend function requires GL_ARB_imaging extension"); } @@ -118,10 +118,10 @@ public class GLBlendElement extends BlendElement { } private void send() { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); // Don't try to optimize what we send to OpenGL at this point -- too complicated if (enabled) { - gl.glEnable(GL.GL_BLEND); + gl.glEnable(GL2.GL_BLEND); int oglSrcFunc = oglBlendFunc(srcFunc); int oglDestFunc = oglBlendFunc(destFunc); validateFunc(gl, oglSrcFunc); @@ -132,7 +132,7 @@ public class GLBlendElement extends BlendElement { gl.glBlendColor(blendColor.x(), blendColor.y(), blendColor.z(), blendColor.w()); } } else { - gl.glDisable(GL.GL_BLEND); + gl.glDisable(GL2.GL_BLEND); } } } diff --git a/src/net/java/joglutils/msg/elements/GLColorElement.java b/src/net/java/joglutils/msg/elements/GLColorElement.java index 732ee98..0503e9a 100644 --- a/src/net/java/joglutils/msg/elements/GLColorElement.java +++ b/src/net/java/joglutils/msg/elements/GLColorElement.java @@ -89,12 +89,12 @@ public class GLColorElement extends ColorElement { if (this.enabled == enabled) return; // No OpenGL work to do this.enabled = enabled; - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); if (enabled) { - gl.glColorPointer(4, GL.GL_FLOAT, 0, colors); - gl.glEnableClientState(GL.GL_COLOR_ARRAY); + gl.glColorPointer(4, GL2.GL_FLOAT, 0, colors); + gl.glEnableClientState(GL2.GL_COLOR_ARRAY); } else { - gl.glDisableClientState(GL.GL_COLOR_ARRAY); + gl.glDisableClientState(GL2.GL_COLOR_ARRAY); // Assume we have to reset the current color to the default gl.glColor4f(1, 1, 1, 1); } diff --git a/src/net/java/joglutils/msg/elements/GLCoordinateElement.java b/src/net/java/joglutils/msg/elements/GLCoordinateElement.java index d33e4ec..aa59690 100644 --- a/src/net/java/joglutils/msg/elements/GLCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/GLCoordinateElement.java @@ -88,12 +88,12 @@ public class GLCoordinateElement extends CoordinateElement { if (this.enabled == enabled) return; // No OpenGL work to do this.enabled = enabled; - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); if (enabled) { - gl.glVertexPointer(3, GL.GL_FLOAT, 0, coords); - gl.glEnableClientState(GL.GL_VERTEX_ARRAY); + gl.glVertexPointer(3, GL2.GL_FLOAT, 0, coords); + gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); } else { - gl.glDisableClientState(GL.GL_VERTEX_ARRAY); + gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); } } } diff --git a/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java b/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java index a63f8ae..c10e436 100644 --- a/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLModelMatrixElement.java @@ -68,7 +68,7 @@ public class GLModelMatrixElement extends ModelMatrixElement { this.state = state; // Cause side-effects in OpenGL - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); gl.glPushMatrix(); } @@ -76,7 +76,7 @@ public class GLModelMatrixElement extends ModelMatrixElement { super.pop(state, previousTopElement); // Cause side-effects in OpenGL - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); gl.glPopMatrix(); } @@ -85,7 +85,7 @@ public class GLModelMatrixElement extends ModelMatrixElement { // Cause side-effects in OpenGL // Recompute the complete modelview matrix Mat4f mat = ViewingMatrixElement.getInstance(state).getMatrix(); - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glLoadTransposeMatrixf(mat.getRowMajorData(), 0); } else { @@ -97,7 +97,7 @@ public class GLModelMatrixElement extends ModelMatrixElement { public void multElt(Mat4f matrix) { super.multElt(matrix); - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glMultTransposeMatrixf(matrix.getRowMajorData(), 0); } else { diff --git a/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java b/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java index 3dfad8f..c811ba4 100644 --- a/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLProjectionMatrixElement.java @@ -67,8 +67,8 @@ public class GLProjectionMatrixElement extends ProjectionMatrixElement { public void setElt(Mat4f matrix) { super.setElt(matrix); - GL gl = GLU.getCurrentGL(); - gl.glMatrixMode(GL.GL_PROJECTION); + GL2 gl = GLU.getCurrentGL().getGL2(); + gl.glMatrixMode(GL2.GL_PROJECTION); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glLoadTransposeMatrixf(matrix.getRowMajorData(), 0); } else { @@ -76,6 +76,6 @@ public class GLProjectionMatrixElement extends ProjectionMatrixElement { matrix.getColumnMajorData(tmp); gl.glLoadMatrixf(tmp, 0); } - gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glMatrixMode(GL2.GL_MODELVIEW); } } diff --git a/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java b/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java index 111d0a9..50a871c 100644 --- a/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java +++ b/src/net/java/joglutils/msg/elements/GLTextureCoordinateElement.java @@ -89,16 +89,16 @@ public class GLTextureCoordinateElement extends TextureCoordinateElement { if (this.enabled == enabled) return; // No OpenGL work to do this.enabled = enabled; - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); if (enabled) { // FIXME: may want to link this up with the GLTextureElement so // that we only enable the texture coordinate array if we both // have a TextureCoordinateElement and a TextureElement active // (a little error checking for the application) - gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, coords); - gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, coords); + gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); } else { - gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); } } } diff --git a/src/net/java/joglutils/msg/elements/GLTextureElement.java b/src/net/java/joglutils/msg/elements/GLTextureElement.java index b5a196d..7f903c3 100644 --- a/src/net/java/joglutils/msg/elements/GLTextureElement.java +++ b/src/net/java/joglutils/msg/elements/GLTextureElement.java @@ -74,7 +74,7 @@ public class GLTextureElement extends TextureElement { } private void switchTextures(Texture2 prev, Texture2 texture) { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); Texture prevTexture = null; Texture curTexture = null; int texEnvMode = 0; @@ -96,12 +96,12 @@ public class GLTextureElement extends TextureElement { curTexture.bind(); int glEnvMode = 0; switch (texEnvMode) { - case Texture2.MODULATE: glEnvMode = GL.GL_MODULATE; break; - case Texture2.DECAL: glEnvMode = GL.GL_DECAL; break; - case Texture2.BLEND: glEnvMode = GL.GL_BLEND; break; - case Texture2.REPLACE: glEnvMode = GL.GL_REPLACE; break; + case Texture2.MODULATE: glEnvMode = GL2.GL_MODULATE; break; + case Texture2.DECAL: glEnvMode = GL2.GL_DECAL; break; + case Texture2.BLEND: glEnvMode = GL2.GL_BLEND; break; + case Texture2.REPLACE: glEnvMode = GL2.GL_REPLACE; break; } - gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, glEnvMode); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, glEnvMode); } } } diff --git a/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java b/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java index a24f53f..cff9fe3 100644 --- a/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java +++ b/src/net/java/joglutils/msg/elements/GLViewingMatrixElement.java @@ -75,7 +75,7 @@ public class GLViewingMatrixElement extends ViewingMatrixElement { // Must push the combined viewing and modelview matrices down to OpenGL Mat4f mdl = ModelMatrixElement.getInstance(state).getMatrix(); temp.mul(matrix, mdl); - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glLoadTransposeMatrixf(temp.getRowMajorData(), 0); } else { diff --git a/src/net/java/joglutils/msg/math/Mat4f.java b/src/net/java/joglutils/msg/math/Mat4f.java index fc4d955..bc7cee0 100644 --- a/src/net/java/joglutils/msg/math/Mat4f.java +++ b/src/net/java/joglutils/msg/math/Mat4f.java @@ -37,6 +37,8 @@ package net.java.joglutils.msg.math; +import java.nio.*; + /** A (very incomplete) 4x4 matrix class. Representation assumes row-major order and multiplication by column vectors on the right. */ @@ -260,12 +262,30 @@ public class Mat4f { } } + /** Copies data in column-major (OpenGL format) order into passed + float buffer, which must have 16 or more remaining elements. */ + public void getColumnMajorData(FloatBuffer out) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + out.put(4 * j + i, get(i, j)); + } + } + } + /** Returns the matrix data in row-major format, which is the opposite of OpenGL's convention. */ public float[] getRowMajorData() { return data; } + /** Stores the matrix data into the passed FloatBuffer in row-major + format, which is the opposite of OpenGL's convention. */ + public void getRowMajorData(FloatBuffer out) { + for (int i = 0; i < 16; i++) { + out.put(i, data[i]); + } + } + public Matf toMatf() { Matf out = new Matf(4, 4); for (int i = 0; i < 4; i++) { diff --git a/src/net/java/joglutils/msg/misc/Shader.java b/src/net/java/joglutils/msg/misc/Shader.java index ab25f78..cf32fc6 100644 --- a/src/net/java/joglutils/msg/misc/Shader.java +++ b/src/net/java/joglutils/msg/misc/Shader.java @@ -36,10 +36,9 @@ package net.java.joglutils.msg.misc; -import javax.media.opengl.GL; -import javax.media.opengl.GLException; +import javax.media.opengl.*; import javax.media.opengl.glu.GLU; -import static javax.media.opengl.GL.*; +import static javax.media.opengl.GL2.*; /** * Represents an OpenGL shader program object, which can be constructed from @@ -89,7 +88,7 @@ public class Shader { public Shader(String fragmentCode) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); id = createProgram(gl, null, fragmentCode); } @@ -110,7 +109,7 @@ public class Shader { public Shader(String vertexCode, String fragmentCode) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); id = createProgram(gl, vertexCode, fragmentCode); } @@ -122,7 +121,7 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - private static int createProgram(GL gl, + private static int createProgram(GL2 gl, String vertexShaderSource, String fragmentShaderSource) throws GLException @@ -201,10 +200,10 @@ public class Shader { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - private static int compileShader(GL gl, String shaderSource, boolean vertex) + private static int compileShader(GL2 gl, String shaderSource, boolean vertex) throws GLException { - int kind = vertex ? GL_VERTEX_SHADER_ARB : GL_FRAGMENT_SHADER_ARB; + int kind = vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; int shader; int[] success = new int[1]; int[] infoLogLength = new int[1]; @@ -255,7 +254,7 @@ public class Shader { * OpenGL-related errors occurred */ public void enable() throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); gl.glUseProgramObjectARB(id); } @@ -266,7 +265,7 @@ public class Shader { * OpenGL-related errors occurred */ public void disable() throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); gl.glUseProgramObjectARB(0); } @@ -277,7 +276,7 @@ public class Shader { * OpenGL-related errors occurred */ public void dispose() throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); gl.glDeleteObjectARB(id); id = 0; } @@ -294,7 +293,7 @@ public class Shader { public void setUniform(String name, int i0) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1iARB(loc, i0); } @@ -312,7 +311,7 @@ public class Shader { public void setUniform(String name, int i0, int i1) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2iARB(loc, i0, i1); } @@ -331,7 +330,7 @@ public class Shader { public void setUniform(String name, int i0, int i1, int i2) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3iARB(loc, i0, i1, i2); } @@ -351,7 +350,7 @@ public class Shader { public void setUniform(String name, int i0, int i1, int i2, int i3) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4iARB(loc, i0, i1, i2, i3); } @@ -368,7 +367,7 @@ public class Shader { public void setUniform(String name, float f0) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1fARB(loc, f0); } @@ -386,7 +385,7 @@ public class Shader { public void setUniform(String name, float f0, float f1) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2fARB(loc, f0, f1); } @@ -405,7 +404,7 @@ public class Shader { public void setUniform(String name, float f0, float f1, float f2) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3fARB(loc, f0, f1, f2); } @@ -425,7 +424,7 @@ public class Shader { public void setUniform(String name, float f0, float f1, float f2, float f3) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4fARB(loc, f0, f1, f2, f3); } @@ -444,7 +443,7 @@ public class Shader { public void setUniformArray1i(String name, int count, int[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1ivARB(loc, count, vals, off); } @@ -463,7 +462,7 @@ public class Shader { public void setUniformArray2i(String name, int count, int[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2ivARB(loc, count, vals, off); } @@ -482,7 +481,7 @@ public class Shader { public void setUniformArray3i(String name, int count, int[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3ivARB(loc, count, vals, off); } @@ -501,7 +500,7 @@ public class Shader { public void setUniformArray4i(String name, int count, int[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4ivARB(loc, count, vals, off); } @@ -521,7 +520,7 @@ public class Shader { int count, float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform1fvARB(loc, count, vals, off); } @@ -541,7 +540,7 @@ public class Shader { int count, float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform2fvARB(loc, count, vals, off); } @@ -561,7 +560,7 @@ public class Shader { int count, float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform3fvARB(loc, count, vals, off); } @@ -581,7 +580,7 @@ public class Shader { int count, float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniform4fvARB(loc, count, vals, off); } @@ -604,7 +603,7 @@ public class Shader { float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix2fvARB(loc, count, transpose, vals, off); } @@ -627,7 +626,7 @@ public class Shader { float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix3fvARB(loc, count, transpose, vals, off); } @@ -650,7 +649,7 @@ public class Shader { float[] vals, int off) throws GLException { - GL gl = GLU.getCurrentGL(); + GL2 gl = GLU.getCurrentGL().getGL2(); int loc = gl.glGetUniformLocationARB(id, name); gl.glUniformMatrix4fvARB(loc, count, transpose, vals, off); } diff --git a/src/net/java/joglutils/msg/nodes/Texture2.java b/src/net/java/joglutils/msg/nodes/Texture2.java index 7844790..9c4cb60 100644 --- a/src/net/java/joglutils/msg/nodes/Texture2.java +++ b/src/net/java/joglutils/msg/nodes/Texture2.java @@ -43,8 +43,9 @@ import java.net.*; import java.util.*; import javax.media.opengl.*; -import com.sun.opengl.util.j2d.*; +import com.sun.opengl.util.awt.*; import com.sun.opengl.util.texture.*; +import com.sun.opengl.util.texture.awt.*; import net.java.joglutils.msg.actions.*; import net.java.joglutils.msg.elements.*; @@ -127,7 +128,7 @@ public class Texture2 extends Node { Texture is fetched. */ public void setTexture(BufferedImage image, boolean mipmap) { disposeTextureRenderer(); - data = TextureIO.newTextureData(image, mipmap); + data = AWTTextureIO.newTextureData(image, mipmap); dirty = true; } diff --git a/src/net/java/joglutils/msg/nodes/TriangleSet.java b/src/net/java/joglutils/msg/nodes/TriangleSet.java index ffa0ea3..4659a19 100644 --- a/src/net/java/joglutils/msg/nodes/TriangleSet.java +++ b/src/net/java/joglutils/msg/nodes/TriangleSet.java @@ -73,7 +73,7 @@ public class TriangleSet extends TriangleBasedShape { if (CoordinateElement.get(state) != null) { // OK, we have coordinates to send down, at least - GL gl = action.getGL(); + GL2 gl = action.getGL(); Texture tex = null; boolean haveTexCoords = false; @@ -90,7 +90,7 @@ public class TriangleSet extends TriangleBasedShape { if (tex != null) { // Set up the texture matrix to uniformly map [0..1] to the used // portion of the texture image - gl.glMatrixMode(GL.GL_TEXTURE); + gl.glMatrixMode(GL2.GL_TEXTURE); gl.glPushMatrix(); if (gl.isExtensionAvailable("GL_VERSION_1_3")) { gl.glLoadTransposeMatrixf(getTextureMatrix(tex).getRowMajorData(), 0); @@ -99,25 +99,25 @@ public class TriangleSet extends TriangleBasedShape { getTextureMatrix(tex).getColumnMajorData(tmp); gl.glLoadMatrixf(tmp, 0); } - gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glMatrixMode(GL2.GL_MODELVIEW); } else if (haveTexCoords) { // Want to turn off the use of texture coordinates to avoid errors // FIXME: not 100% sure whether we need to do this, but think we should - gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); } // For now, assume the triangle set and the number of available // coordinates match -- may want to add debugging information // for this later - gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3 * getNumTriangles()); + gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 3 * getNumTriangles()); if (tex != null) { - gl.glMatrixMode(GL.GL_TEXTURE); + gl.glMatrixMode(GL2.GL_TEXTURE); gl.glPopMatrix(); - gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glMatrixMode(GL2.GL_MODELVIEW); } else if (haveTexCoords) { // Might want this the next time we render a shape - gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); + gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); } } } diff --git a/src/net/java/joglutils/msg/test/DisplayShelf.java b/src/net/java/joglutils/msg/test/DisplayShelf.java index de08225..1e3bab7 100644 --- a/src/net/java/joglutils/msg/test/DisplayShelf.java +++ b/src/net/java/joglutils/msg/test/DisplayShelf.java @@ -48,6 +48,7 @@ import java.net.*; import javax.swing.*; import javax.media.opengl.*; +import javax.media.opengl.awt.*; /** * A test implementing a 3D display shelf component. @@ -134,7 +135,7 @@ public class DisplayShelf { } DisplayShelfRenderer renderer = new DisplayShelfRenderer(model); - GLCanvas canvas = new GLCanvas(new GLCapabilities(), null, renderer.getSharedContext(), null); + GLCanvas canvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()), null, renderer.getSharedContext(), null); canvas.setFocusable(true); canvas.addGLEventListener(renderer); f.add(canvas); diff --git a/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java b/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java index adf1263..5cdffc1 100644 --- a/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java +++ b/src/net/java/joglutils/msg/test/DisplayShelfRenderer.java @@ -49,7 +49,8 @@ import javax.swing.*; import javax.swing.event.*; import javax.media.opengl.*; -import com.sun.opengl.util.j2d.*; +import javax.media.opengl.awt.*; +import com.sun.opengl.util.awt.*; import net.java.joglutils.msg.actions.*; import net.java.joglutils.msg.collections.*; @@ -99,7 +100,7 @@ public class DisplayShelfRenderer implements GLEventListener { private GLPbuffer sharedPbuffer; private boolean firstInit = true; - private GLAutoDrawable drawable; + private AWTGLAutoDrawable drawable; private Separator root; private Separator imageRoot; @@ -154,7 +155,7 @@ public class DisplayShelfRenderer implements GLEventListener { // Create a small pbuffer with which we share textures and display // lists to avoid having to reload textures during repeated calls // to init() - sharedPbuffer = GLDrawableFactory.getFactory().createGLPbuffer(new GLCapabilities(), null, 1, 1, null); + sharedPbuffer = GLDrawableFactory.getFactory(GLProfile.getDefault()).createGLPbuffer(new GLCapabilities(GLProfile.getDefault()), null, 1, 1, null); sharedPbuffer.display(); this.fetcher = new BasicFetcher<Integer>(); @@ -221,8 +222,8 @@ public class DisplayShelfRenderer implements GLEventListener { return targetIndex; } - public void init(GLAutoDrawable drawable) { - this.drawable = drawable; + public void init(GLAutoDrawable d) { + this.drawable = (AWTGLAutoDrawable) d; GL gl = drawable.getGL(); if (firstInit) { @@ -407,7 +408,7 @@ public class DisplayShelfRenderer implements GLEventListener { if (repaintAgain) { animating = true; - drawable.repaint(); + ((AWTGLAutoDrawable) drawable).repaint(); } else { animating = false; } @@ -416,7 +417,7 @@ public class DisplayShelfRenderer implements GLEventListener { public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + public void dispose(GLAutoDrawable drawable) {} //---------------------------------------------------------------------- // Internals only below this point diff --git a/src/net/java/joglutils/msg/test/Test.java b/src/net/java/joglutils/msg/test/Test.java index a782e3e..d54d31b 100644 --- a/src/net/java/joglutils/msg/test/Test.java +++ b/src/net/java/joglutils/msg/test/Test.java @@ -35,116 +35,117 @@ * */ -package net.java.joglutils.msg.test;
-
-import java.awt.Frame;
-import java.awt.event.*;
-import java.io.*;
-
-import javax.media.opengl.*;
-import com.sun.opengl.util.texture.*;
-
-import net.java.joglutils.msg.actions.*;
-import net.java.joglutils.msg.collections.*;
-import net.java.joglutils.msg.math.*;
-import net.java.joglutils.msg.nodes.*;
-
-/** A very basic test of the Minimal Scene Graph library. */
-
-public class Test {
- public static void main(String[] args) {
- Frame frame = new Frame("Minimal Scene Graph (MSG) Test");
- GLCanvas canvas = new GLCanvas();
- canvas.addGLEventListener(new Listener());
- frame.add(canvas);
- frame.setSize(512, 512);
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- new Thread(new Runnable() {
- public void run() {
- System.exit(0);
- }
- }).start();
- }
- });
- }
-
- static class Listener implements GLEventListener {
- private Separator root;
- private GLRenderAction renderAction;
-
- public void init(GLAutoDrawable drawable) {
- root = new Separator();
- PerspectiveCamera cam = new PerspectiveCamera();
- cam.setPosition(new Vec3f(0, 0, 2));
- root.addChild(cam);
- Coordinate3 coordNode = new Coordinate3();
- Vec3fCollection coords = new Vec3fCollection();
- // First triangle
- coords.add(new Vec3f( 1, 1, 0));
- coords.add(new Vec3f(-1, 1, 0));
- coords.add(new Vec3f(-1, -1, 0));
- // Second triangle
- coords.add(new Vec3f( 1, 1, 0));
- coords.add(new Vec3f(-1, -1, 0));
- coords.add(new Vec3f( 1, -1, 0));
- coordNode.setData(coords);
- root.addChild(coordNode);
-
- // Texture coordinates
- TextureCoordinate2 texCoordNode = new TextureCoordinate2();
- Vec2fCollection texCoords = new Vec2fCollection();
- // First triangle
- texCoords.add(new Vec2f( 1, 1));
- texCoords.add(new Vec2f( 0, 1));
- texCoords.add(new Vec2f( 0, 0));
- // Second triangle
- texCoords.add(new Vec2f( 1, 1));
- texCoords.add(new Vec2f( 0, 0));
- texCoords.add(new Vec2f( 1, 0));
- texCoordNode.setData(texCoords);
- root.addChild(texCoordNode);
-
- // Colors
- Color4 colorNode = new Color4();
- Vec4fCollection colors = new Vec4fCollection();
- // First triangle
- colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
- colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
- colors.add(new Vec4f(0.0f, 0.0f, 0.0f, 0.0f));
- // Second triangle
- colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
- colors.add(new Vec4f(0.0f, 0.0f, 0.0f, 0.0f));
- colors.add(new Vec4f(0.0f, 0.0f, 0.0f, 0.0f));
- colorNode.setData(colors);
- root.addChild(colorNode);
-
- TriangleSet tris = new TriangleSet();
- tris.setNumTriangles(2);
- root.addChild(tris);
-
- // Testing transforms
- Transform xform = new Transform();
- xform.getTransform().setTranslation(new Vec3f(2, -2, 0));
- // xform.getTransform().setRotation(new Rotf(new Vec3f(0, 1, 0), (float) (-Math.PI / 4)));
- root.addChild(xform);
-
- root.addChild(tris);
-
- GL gl = drawable.getGL();
- gl.glEnable(GL.GL_DEPTH_TEST);
-
- renderAction = new GLRenderAction();
- }
-
- public void display(GLAutoDrawable drawable) {
- GL gl = drawable.getGL();
- gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- renderAction.apply(root);
- }
-
- public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {}
- public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
- }
-}
+package net.java.joglutils.msg.test; + +import java.awt.Frame; +import java.awt.event.*; +import java.io.*; + +import javax.media.opengl.*; +import javax.media.opengl.awt.*; +import com.sun.opengl.util.texture.*; + +import net.java.joglutils.msg.actions.*; +import net.java.joglutils.msg.collections.*; +import net.java.joglutils.msg.math.*; +import net.java.joglutils.msg.nodes.*; + +/** A very basic test of the Minimal Scene Graph library. */ + +public class Test { + public static void main(String[] args) { + Frame frame = new Frame("Minimal Scene Graph (MSG) Test"); + GLCanvas canvas = new GLCanvas(); + canvas.addGLEventListener(new Listener()); + frame.add(canvas); + frame.setSize(512, 512); + frame.setVisible(true); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + new Thread(new Runnable() { + public void run() { + System.exit(0); + } + }).start(); + } + }); + } + + static class Listener implements GLEventListener { + private Separator root; + private GLRenderAction renderAction; + + public void init(GLAutoDrawable drawable) { + root = new Separator(); + PerspectiveCamera cam = new PerspectiveCamera(); + cam.setPosition(new Vec3f(0, 0, 2)); + root.addChild(cam); + Coordinate3 coordNode = new Coordinate3(); + Vec3fCollection coords = new Vec3fCollection(); + // First triangle + coords.add(new Vec3f( 1, 1, 0)); + coords.add(new Vec3f(-1, 1, 0)); + coords.add(new Vec3f(-1, -1, 0)); + // Second triangle + coords.add(new Vec3f( 1, 1, 0)); + coords.add(new Vec3f(-1, -1, 0)); + coords.add(new Vec3f( 1, -1, 0)); + coordNode.setData(coords); + root.addChild(coordNode); + + // Texture coordinates + TextureCoordinate2 texCoordNode = new TextureCoordinate2(); + Vec2fCollection texCoords = new Vec2fCollection(); + // First triangle + texCoords.add(new Vec2f( 1, 1)); + texCoords.add(new Vec2f( 0, 1)); + texCoords.add(new Vec2f( 0, 0)); + // Second triangle + texCoords.add(new Vec2f( 1, 1)); + texCoords.add(new Vec2f( 0, 0)); + texCoords.add(new Vec2f( 1, 0)); + texCoordNode.setData(texCoords); + root.addChild(texCoordNode); + + // Colors + Color4 colorNode = new Color4(); + Vec4fCollection colors = new Vec4fCollection(); + // First triangle + colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + colors.add(new Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); + // Second triangle + colors.add(new Vec4f(1.0f, 1.0f, 1.0f, 1.0f)); + colors.add(new Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); + colors.add(new Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); + colorNode.setData(colors); + root.addChild(colorNode); + + TriangleSet tris = new TriangleSet(); + tris.setNumTriangles(2); + root.addChild(tris); + + // Testing transforms + Transform xform = new Transform(); + xform.getTransform().setTranslation(new Vec3f(2, -2, 0)); + // xform.getTransform().setRotation(new Rotf(new Vec3f(0, 1, 0), (float) (-Math.PI / 4))); + root.addChild(xform); + + root.addChild(tris); + + GL gl = drawable.getGL(); + gl.glEnable(GL.GL_DEPTH_TEST); + + renderAction = new GLRenderAction(); + } + + public void display(GLAutoDrawable drawable) { + GL gl = drawable.getGL(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + renderAction.apply(root); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {} + public void dispose(GLAutoDrawable drawable) {} + } +} |