diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java | 2 | ||||
-rwxr-xr-x | src/demos/hdr/HDR.java | 6 | ||||
-rwxr-xr-x | src/demos/hdr/HDRTexture.java | 41 | ||||
-rw-r--r-- | src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java | 2 | ||||
-rw-r--r-- | src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java | 5 | ||||
-rw-r--r-- | src/demos/proceduralTexturePhysics/Water.java | 7 | ||||
-rw-r--r-- | src/demos/vertexArrayRange/VertexArrayRange.java | 25 | ||||
-rw-r--r-- | src/demos/vertexBufferObject/VertexBufferObject.java | 42 | ||||
-rw-r--r-- | src/demos/vertexProgRefract/VertexProgRefract.java | 4 |
9 files changed, 64 insertions, 70 deletions
diff --git a/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java b/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java index fec2bee..4ecb5db 100644 --- a/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java +++ b/src/demos/cg/runtime_ogl_vertex_fragment/runtime_ogl_vertex_fragment.java @@ -303,7 +303,7 @@ public class runtime_ogl_vertex_fragment implements GLEventListener } } - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, RES, RES, 0, GL.GL_RGBA, GL.GL_FLOAT, data, 0); + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, RES, RES, 0, GL.GL_RGBA, GL.GL_FLOAT, FloatBuffer.wrap(data)); // Tell Cg which texture handle should be associated with the sampler2D // parameter to the fragment shader. diff --git a/src/demos/hdr/HDR.java b/src/demos/hdr/HDR.java index d3db51f..fe70b5b 100755 --- a/src/demos/hdr/HDR.java +++ b/src/demos/hdr/HDR.java @@ -511,7 +511,7 @@ public class HDR implements GLEventListener { img[i] = (float) Math.pow(x, gamma); } - gl.glTexImage1D(target, 0, GL.GL_LUMINANCE, size, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, img, 0); + gl.glTexImage1D(target, 0, GL.GL_LUMINANCE, size, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, FloatBuffer.wrap(img)); return texid; } @@ -551,7 +551,7 @@ public class HDR implements GLEventListener { } } - gl.glTexImage2D(GL.GL_TEXTURE_RECTANGLE_NV, 0, GL.GL_LUMINANCE, xsiz, ysiz, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, img, 0); + gl.glTexImage2D(GL.GL_TEXTURE_RECTANGLE_NV, 0, GL.GL_LUMINANCE, xsiz, ysiz, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, FloatBuffer.wrap(img)); return texid; } @@ -738,7 +738,7 @@ public class HDR implements GLEventListener { gl.glVertexPointer(3, GL.GL_FLOAT, 0, model.getVertices()); gl.glNormalPointer(GL.GL_FLOAT, 0, model.getVertexNormals()); int[] indices = model.getFaceIndices(); - gl.glDrawElements(GL.GL_TRIANGLES, indices.length, GL.GL_UNSIGNED_INT, indices, 0); + gl.glDrawElements(GL.GL_TRIANGLES, indices.length, GL.GL_UNSIGNED_INT, IntBuffer.wrap(indices)); gl.glDisableClientState(GL.GL_VERTEX_ARRAY); gl.glDisableClientState(GL.GL_NORMAL_ARRAY); break; diff --git a/src/demos/hdr/HDRTexture.java b/src/demos/hdr/HDRTexture.java index f5cf829..9112131 100755 --- a/src/demos/hdr/HDRTexture.java +++ b/src/demos/hdr/HDRTexture.java @@ -1,6 +1,7 @@ package demos.hdr; import java.io.*; +import java.nio.*; import net.java.games.jogl.*; @@ -106,7 +107,7 @@ public class HDRTexture { gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glTexParameteri(m_target, GL.GL_GENERATE_MIPMAP_SGIS, GL.GL_TRUE); - gl.glTexImage2D(m_target, 0, GL.GL_RGBA, m_width, m_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, m_data, 0); + gl.glTexImage2D(m_target, 0, GL.GL_RGBA, m_width, m_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(m_data)); return texid; } @@ -143,7 +144,7 @@ public class HDRTexture { } } - gl.glTexImage2D(m_target, 0, GL.GL_HILO16_NV, m_width, m_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, img, 0); + gl.glTexImage2D(m_target, 0, GL.GL_HILO16_NV, m_width, m_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(img)); return texid; } @@ -184,7 +185,7 @@ public class HDRTexture { face[ptr++] = m_data[src++]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(face)); // positive X ptr = 0; @@ -197,7 +198,7 @@ public class HDRTexture { face[ptr++] = m_data[src++]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(face)); // negative Z ptr = 0; @@ -210,7 +211,7 @@ public class HDRTexture { face[ptr++] = m_data[src++]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(face)); // negative X ptr = 0; @@ -223,7 +224,7 @@ public class HDRTexture { face[ptr++] = m_data[src++]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(face)); // negative Y ptr = 0; @@ -236,7 +237,7 @@ public class HDRTexture { face[ptr++] = m_data[src++]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(face)); // positive Z ptr = 0; @@ -249,7 +250,7 @@ public class HDRTexture { face[ptr++] = m_data[src++]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL.GL_RGBA, face_width, face_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(face)); return texid; } @@ -290,7 +291,7 @@ public class HDRTexture { } } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(face)); // positive X ptr = 0; @@ -306,7 +307,7 @@ public class HDRTexture { } } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(face)); // negative Z ptr = 0; @@ -322,7 +323,7 @@ public class HDRTexture { } } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(face)); // negative X ptr = 0; @@ -338,7 +339,7 @@ public class HDRTexture { } } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(face)); // negative Y ptr = 0; @@ -354,7 +355,7 @@ public class HDRTexture { } } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(face)); // positive Z ptr = 0; @@ -370,7 +371,7 @@ public class HDRTexture { } } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL.GL_HILO16_NV, face_width, face_height, 0, GL.GL_HILO_NV, GL.GL_FLOAT, FloatBuffer.wrap(face)); return texid; } @@ -407,7 +408,7 @@ public class HDRTexture { face[ptr++] = m_floatdata[src + 2]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, FloatBuffer.wrap(face)); // positive X ptr = 0; @@ -419,7 +420,7 @@ public class HDRTexture { face[ptr++] = m_floatdata[src + 2]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, FloatBuffer.wrap(face)); // negative Z ptr = 0; @@ -431,7 +432,7 @@ public class HDRTexture { face[ptr++] = m_floatdata[src + 2]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, FloatBuffer.wrap(face)); // negative X ptr = 0; @@ -443,7 +444,7 @@ public class HDRTexture { face[ptr++] = m_floatdata[src + 2]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, FloatBuffer.wrap(face)); // negative Y ptr = 0; @@ -455,7 +456,7 @@ public class HDRTexture { face[ptr++] = m_floatdata[src + 2]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, FloatBuffer.wrap(face)); // positive Z ptr = 0; @@ -467,7 +468,7 @@ public class HDRTexture { face[ptr++] = m_floatdata[src + 2]; } } - gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, face, 0); + gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, format, face_width, face_height, 0, GL.GL_RGB, GL.GL_FLOAT, FloatBuffer.wrap(face)); return texid; } diff --git a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java index 8a0cdfc..aba8d95 100644 --- a/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java +++ b/src/demos/hwShadowmapsSimple/HWShadowmapsSimple.java @@ -408,7 +408,7 @@ public class HWShadowmapsSimple implements GLEventListener { light_view_depth = genTexture(gl); gl.glBindTexture(GL.GL_TEXTURE_2D, light_view_depth); gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, depth_format, TEX_SIZE, TEX_SIZE, 0, - GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_INT, (byte[]) null, 0); + GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_INT, null); set_light_view_texture_parameters(gl); fullyInitialized = true; diff --git a/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java b/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java index 2731fa3..cb913b9 100644 --- a/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java +++ b/src/demos/infiniteShadowVolumes/InfiniteShadowVolumes.java @@ -196,6 +196,7 @@ public class InfiniteShadowVolumes implements GLEventListener { gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP_SGIS, GL.GL_TRUE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); + float[] tex = new float[32*32]; for(int i=0; i < 32; i++) { for(int j=0; j < 32; j++) { @@ -205,10 +206,10 @@ public class InfiniteShadowVolumes implements GLEventListener { tex[i+j*32] = .9f; } } - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 32, 32, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, tex, 0); + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 32, 32, 0, GL.GL_LUMINANCE, GL.GL_FLOAT, FloatBuffer.wrap(tex)); initModel(); - + b['S'] = true; // no silhouette outlines b['v'] = true; // no volume drawing b['I'] = true; // use infinite far plane diff --git a/src/demos/proceduralTexturePhysics/Water.java b/src/demos/proceduralTexturePhysics/Water.java index 682232b..7113161 100644 --- a/src/demos/proceduralTexturePhysics/Water.java +++ b/src/demos/proceduralTexturePhysics/Water.java @@ -36,6 +36,7 @@ package demos.proceduralTexturePhysics; import java.awt.Image; import java.awt.image.*; import java.io.*; +import java.nio.*; import java.text.*; import java.util.*; @@ -1013,8 +1014,7 @@ public class Water { 0, image.getGLFormat(), GL.GL_UNSIGNED_BYTE, - image.getData(), - 0); + ByteBuffer.wrap(image.getData())); gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); @@ -1057,8 +1057,7 @@ public class Water { 0, image.getGLFormat(), GL.GL_UNSIGNED_BYTE, - image.getData(), - 0); + ByteBuffer.wrap(image.getData())); } } diff --git a/src/demos/vertexArrayRange/VertexArrayRange.java b/src/demos/vertexArrayRange/VertexArrayRange.java index c131a44..5b92d0a 100644 --- a/src/demos/vertexArrayRange/VertexArrayRange.java +++ b/src/demos/vertexArrayRange/VertexArrayRange.java @@ -40,6 +40,7 @@ import java.util.*; import javax.swing.*; import net.java.games.jogl.*; +import net.java.games.jogl.util.*; import demos.util.*; /** <P> A port of NVidia's [tm] Vertex Array Range demonstration to @@ -97,6 +98,7 @@ public class VertexArrayRange implements GLEventListener { canvas.addGLEventListener(demo); final Animator animator = new Animator(canvas); + animator.setRunAsFastAsPossible(true); demo.setDemoListener(new DemoListener() { public void shutdownDemo() { runExit(animator); @@ -105,6 +107,11 @@ public class VertexArrayRange implements GLEventListener { }); Frame frame = new Frame("Very Simple NV_vertex_array_range demo"); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + runExit(animator); + } + }); frame.setLayout(new BorderLayout()); canvas.setSize(800, 800); frame.add(canvas, BorderLayout.CENTER); @@ -112,12 +119,6 @@ public class VertexArrayRange implements GLEventListener { frame.show(); canvas.requestFocus(); - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - runExit(animator); - } - }); - animator.start(); } @@ -154,7 +155,7 @@ public class VertexArrayRange implements GLEventListener { private FloatBuffer bigArrayVar; private FloatBuffer bigArraySystem; private FloatBuffer bigArray; - private int[][] elements; + private IntBuffer[] elements; private float[] xyArray; static class VarBuffer { @@ -606,7 +607,7 @@ public class VertexArrayRange implements GLEventListener { for (int i = 0; i < elements.length; i++) { ++numDrawElementsCalls; - gl.glDrawElements(primitive, elements[i].length, GL.GL_UNSIGNED_INT, elements[i], 0); + gl.glDrawElements(primitive, elements[i].capacity(), GL.GL_UNSIGNED_INT, elements[i]); if(getFlag('f')) { gl.glFlush(); } @@ -698,12 +699,12 @@ public class VertexArrayRange implements GLEventListener { xyArray[i] = i / (tileSize - 1.0f) - 0.5f; } - elements = new int[tileSize - 1][]; + elements = new IntBuffer[tileSize - 1]; for (int i = 0; i < tileSize - 1; i++) { - elements[i] = new int[2 * STRIP_SIZE]; + elements[i] = IntBuffer.allocate(2 * STRIP_SIZE); for (int j = 0; j < 2 * STRIP_SIZE; j += 2) { - elements[i][j] = i * STRIP_SIZE + (j / 2); - elements[i][j+1] = (i + 1) * STRIP_SIZE + (j / 2); + elements[i].put(j, i * STRIP_SIZE + (j / 2)); + elements[i].put(j+1, (i + 1) * STRIP_SIZE + (j / 2)); } } } diff --git a/src/demos/vertexBufferObject/VertexBufferObject.java b/src/demos/vertexBufferObject/VertexBufferObject.java index 2c5ece4..d06994e 100644 --- a/src/demos/vertexBufferObject/VertexBufferObject.java +++ b/src/demos/vertexBufferObject/VertexBufferObject.java @@ -88,6 +88,7 @@ public class VertexBufferObject implements GLEventListener { canvas.addGLEventListener(demo); final Animator animator = new Animator(canvas); + animator.setRunAsFastAsPossible(true); demo.setDemoListener(new DemoListener() { public void shutdownDemo() { runExit(animator); @@ -96,6 +97,11 @@ public class VertexBufferObject implements GLEventListener { }); Frame frame = new Frame("Very Simple vertex_buffer_object demo"); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + runExit(animator); + } + }); frame.setLayout(new BorderLayout()); canvas.setSize(800, 800); frame.add(canvas, BorderLayout.CENTER); @@ -103,20 +109,6 @@ public class VertexBufferObject implements GLEventListener { frame.show(); canvas.requestFocus(); - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - // Run this on another thread than the AWT event queue to - // make sure the call to Animator.stop() completes before - // exiting - new Thread(new Runnable() { - public void run() { - animator.stop(); - System.exit(0); - } - }).start(); - } - }); - animator.start(); } @@ -158,7 +150,7 @@ public class VertexBufferObject implements GLEventListener { private FloatBuffer bigArrayVBO; private FloatBuffer bigArraySystem; private FloatBuffer bigArray; - private int[][] elements; + private IntBuffer[] elements; private int elementBufferObject; private float[] xyArray; @@ -650,7 +642,7 @@ public class VertexBufferObject implements GLEventListener { } else { for (int i = 0; i < elements.length; i++) { ++numDrawElementsCalls; - gl.glDrawElements(primitive, elements[i].length, GL.GL_UNSIGNED_INT, elements[i], 0); + gl.glDrawElements(primitive, elements[i].remaining(), GL.GL_UNSIGNED_INT, elements[i]); if(getFlag('f')) { gl.glFlush(); } @@ -725,22 +717,22 @@ public class VertexBufferObject implements GLEventListener { xyArray[i] = i / (tileSize - 1.0f) - 0.5f; } - elements = new int[tileSize - 1][]; + elements = new IntBuffer[tileSize - 1]; for (int i = 0; i < tileSize - 1; i++) { - elements[i] = new int[2 * STRIP_SIZE]; + elements[i] = IntBuffer.allocate(2 * STRIP_SIZE); for (int j = 0; j < 2 * STRIP_SIZE; j += 2) { - elements[i][j] = i * STRIP_SIZE + (j / 2); - elements[i][j+1] = (i + 1) * STRIP_SIZE + (j / 2); + elements[i].put(j, i * STRIP_SIZE + (j / 2)); + elements[i].put(j+1, (i + 1) * STRIP_SIZE + (j / 2)); } } // Create element array buffer - int[] linearElements = new int[(tileSize - 1) * (2 * STRIP_SIZE)]; + IntBuffer linearElements = IntBuffer.allocate((tileSize - 1) * (2 * STRIP_SIZE)); int idx = 0; for (int i = 0; i < tileSize - 1; i++) { for (int j = 0; j < 2 * STRIP_SIZE; j += 2) { - linearElements[idx++] = i * STRIP_SIZE + (j / 2); - linearElements[idx++] = (i + 1) * STRIP_SIZE + (j / 2); + linearElements.put(idx++, i * STRIP_SIZE + (j / 2)); + linearElements.put(idx++, (i + 1) * STRIP_SIZE + (j / 2)); } } int[] tmp = new int[1]; @@ -748,8 +740,8 @@ public class VertexBufferObject implements GLEventListener { elementBufferObject = tmp[0]; gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, elementBufferObject); gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, - linearElements.length * BufferUtils.SIZEOF_INT, - linearElements, 0, + linearElements.remaining() * BufferUtils.SIZEOF_INT, + linearElements, GL.GL_STATIC_DRAW_ARB); gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, 0); } diff --git a/src/demos/vertexProgRefract/VertexProgRefract.java b/src/demos/vertexProgRefract/VertexProgRefract.java index e3444cd..53b0bb5 100644 --- a/src/demos/vertexProgRefract/VertexProgRefract.java +++ b/src/demos/vertexProgRefract/VertexProgRefract.java @@ -533,7 +533,7 @@ public class VertexProgRefract implements GLEventListener { GL.GL_UNSIGNED_BYTE, data); } else { gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0, - GL.GL_RGB, GL.GL_UNSIGNED_BYTE, data, 0); + GL.GL_RGB, GL.GL_UNSIGNED_BYTE, ByteBuffer.wrap(data)); } break; } @@ -545,7 +545,7 @@ public class VertexProgRefract implements GLEventListener { GL.GL_UNSIGNED_BYTE, data); } else { gl.glTexImage2D(target, 0, GL.GL_RGB, img.getWidth(), img.getHeight(), 0, - GL.GL_RGB, GL.GL_UNSIGNED_BYTE, data, 0); + GL.GL_RGB, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(data)); } break; } |