I am using the last pre-JSR version of JOGL. I know, I know, I will switch soon, but because the API isn’t compatible, it isn’t totally painless. In the meantime, I am trying to call VBO as follows. The code crashes on the drawArrays call. I am passing a null in for the buffer, but as far as I understand VBO (and that’s not much) I’m not actually using the array. In the C API, it’s passed as a NULL.
public void displayGL(Viewer v) {
GL gl = v.getGL();
if (first) {
xyz = new float[numVertices*3];
genGrid(xyz);
boolean vbo = checkIfSupported(gl, "GL_ARB_vertex_buffer_object");
System.out.println("Checking for VBO:" + vbo);
if (vbo) {
bufferId = new int[1];
gl.glGenBuffersARB(1, bufferId);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, bufferId[0]);
gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, numVertices*3, xyz, GL.GL_STATIC_DRAW_ARB);
//xyz = FloatBuffer.allocate(numVertices*3);
xyz = null; // free local data, no longer needed
}
first = false;
}
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
gl.glColor3f(0,0,0);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, numVertices);
==> gl.glVertexPointer(3, GL.GL_FLOAT, 0, null);
==> gl.glDrawArrays(GL.GL_TRIANGLES, 0, bufferId[0]);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
}