LWJGL Forum

Programming => OpenGL => Topic started by: TimmerCA on March 17, 2012, 18:55:16

Title: Cannot use offsets when Array Buffer Object is disabled
Post by: TimmerCA on March 17, 2012, 18:55:16
I'm trying to use glDrawElements with an interleaved VBO, like this:

GL11.glEnable(GL31.GL_PRIMITIVE_RESTART);
GL11.glEnable(GL15.GL_ARRAY_BUFFER_BINDING);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);

GL11.glVertexPointer(3, GL11.GL_FLOAT, 40, 0);
GL11.glNormalPointer(GL11.GL_FLOAT, 40, 12);
GL11.glColorPointer(4, GL11.GL_FLOAT, 40, 24);

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, index_buffer_id);

GL12.glDrawRangeElements(
  GL11.GL_TRIANGLE_STRIP,
  0,
  number_of_indexes,
  number_of_indexes,
  GL11.GL_UNSIGNED_INT,
  0
);


But, I'm getting the following error on the glVertexPointer call:

Cannot use offsets when Array Buffer Object is disabled

I don't understand what I'm doing incorrectly.  I looked at the LWJGL source code that emits that error, and it seems to be checking for GL15.GL_ARRAY_BUFFER_BINDING, which I've enabled in my code.  What am I doing wrong?
Title: Re: Cannot use offsets when Array Buffer Object is disabled
Post by: spasi on March 17, 2012, 19:28:06
You need to call:

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);

Before:

GL11.glVertexPointer(3, GL11.GL_FLOAT, 40, 0);
GL11.glNormalPointer(GL11.GL_FLOAT, 40, 12);
GL11.glColorPointer(4, GL11.GL_FLOAT, 40, 24);


The last parameter in the *Pointer calls is an offset relative to the start of the currently bound VBO. In your case, you don't have a VBO bound when you make those calls. If LWJGL didn't perform that check, your JVM would crash.

Also, this:

GL11.glEnable(GL15.GL_ARRAY_BUFFER_BINDING);

should be causing an OpenGL error. GL_ARRAY_BUFFER_BINDING is only usable with glGetInteger.
Title: Re: Cannot use offsets when Array Buffer Object is disabled
Post by: TimmerCA on March 17, 2012, 20:23:22
Quote from: spasi on March 17, 2012, 19:28:06
You need to call:

GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);

Before:

GL11.glVertexPointer(3, GL11.GL_FLOAT, 40, 0);
GL11.glNormalPointer(GL11.GL_FLOAT, 40, 12);
GL11.glColorPointer(4, GL11.GL_FLOAT, 40, 24);


The last parameter in the *Pointer calls is an offset relative to the start of the currently bound VBO. In your case, you don't have a VBO bound when you make those calls. If LWJGL didn't perform that check, your JVM would crash.

Also, this:

GL11.glEnable(GL15.GL_ARRAY_BUFFER_BINDING);

should be causing an OpenGL error. GL_ARRAY_BUFFER_BINDING is only usable with glGetInteger.

Got it, thanks!  I've changed the order of the calls and dropped the call to GL11.glEnable(GL15.GL_ARRAY_BUFFER_BINDING); and it is working properly now.