LWJGL

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Cannot use offsets when Array Buffer Object is disabled  (Read 5454 times)

TimmerCA

  • Newbie
  • *
  • Offline Offline
  • Posts: 18
Cannot use offsets when Array Buffer Object is disabled
« on: March 17, 2012, 18:55:16 »

I'm trying to use glDrawElements with an interleaved VBO, like this:

Code: [Select]
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:

Code: [Select]
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?
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Online Online
  • Posts: 1017
Re: Cannot use offsets when Array Buffer Object is disabled
« Reply #1 on: March 17, 2012, 19:28:06 »

You need to call:

Code: [Select]
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);
Before:

Code: [Select]
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:

Code: [Select]
GL11.glEnable(GL15.GL_ARRAY_BUFFER_BINDING);
should be causing an OpenGL error. GL_ARRAY_BUFFER_BINDING is only usable with glGetInteger.
Logged

TimmerCA

  • Newbie
  • *
  • Offline Offline
  • Posts: 18
Re: Cannot use offsets when Array Buffer Object is disabled
« Reply #2 on: March 17, 2012, 20:23:22 »

You need to call:

Code: [Select]
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);
Before:

Code: [Select]
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:

Code: [Select]
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.
Logged