LWJGL
October 24, 2014, 22:32:17 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.9.1 released!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Cannot use offsets when Array Buffer Object is disabled  (Read 4905 times)
TimmerCA
Newbie
*
Posts: 18



WWW
« on: March 17, 2012, 11:55:16 »

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

Code:
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:
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
*****
Posts: 864



WWW
« Reply #1 on: March 17, 2012, 12:28:06 »

You need to call:

Code:
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);

Before:

Code:
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:
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
*
Posts: 18



WWW
« Reply #2 on: March 17, 2012, 13:23:22 »

You need to call:

Code:
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertex_buffer_id);

Before:

Code:
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:
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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!