I’m trying to convert some rendering code that uses plain glVertex() calls and the like into code that uses vertex arrays but without luck so far.
Hopefully there’s someone willing to take a look at what’s wrong with the following code? Old a new code are mixed using a boolean to determine which to use for rendering, but they should do exactly the same. The “old” code works so you can assume that basic setup and such works correctly. But ofcourse I can post the complete source if necessary.
Any help would be much appreciated.
Cheers,
-Tako
init():
if (useArrays) {
vertBuf = ByteBuffer.allocateDirect(12 * 4).asFloatBuffer();
texBuf = ByteBuffer.allocateDirect(8 * 4).asFloatBuffer();
texBuf.put(0.0f).put(0.0f);
vertBuf.put(-1.0f).put(-1.0f).put(1.0f);
texBuf.put(1.0f).put(0.0f);
vertBuf.put(1.0f).put(-1.0f).put(1.0f);
texBuf.put(1.0f).put(1.0f);
vertBuf.put(1.0f).put(1.0f).put(1.0f);
texBuf.put(0.0f).put(1.0f);
vertBuf.put(-1.0f).put(1.0f).put(1.0f);
} else {
list = gl.glGenLists(1);
gl.glNewList(list, GL.GL_COMPILE);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3f(-1.0f, -1.0f, 1.0f);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3f(1.0f, -1.0f, 1.0f);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3f(1.0f, 1.0f, 1.0f);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3f(-1.0f, 1.0f, 1.0f);
gl.glEndList();
}
display():
if (useArrays) {
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL.GL_FLOAT, 3 * 4, vertBuf);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 2 * 4, texBuf);
gl.glDrawArrays(GL.GL_QUADS, 0, 4);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
} else {
gl.glBegin(GL.GL_QUADS);
gl.glCallList(list);
gl.glEnd();
}