VBO, BUFFER_OFFSET and glDrawElements broken?

Hi

I’m trying to render only a part of an VBO-element-buffer, so I don’t need to switch buffers all the time. It doesn’t seem to work though. I don’t see any sane reason why this shouldn’t work, but if you know one, please enlighten me :slight_smile:

This is the code I’m using. It’s supposed to render two triangles from somewhere (here the second triangle) in the element-buffer. It doesn’t render anything though.

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

glBindBufferARB( GL_ARRAY_BUFFER_ARB, pos_buf );
glVertexPointer( no_verts, GL_FLOAT, 0, 0 );
glEnableClientState(GL_VERTEX_ARRAY);	

glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, elem_buf );

glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_INT, BUFFER_OFFSET(3) );

Regards,

The buffer offset is in bytes which means you are part way through one float when you render your primitive. Presumably you mean BUFFER_OFFSET(3*sizeof(GLfloat)).

Matt

Ah! Thanks a lot, it works now.

Actually it was supposed to be BUFFER_OFFSET(3*sizeof(GLuint)) as my element-indices are unsigned int.

Switching buffers is a relatively lightweight operation. Using DrawRangeElements is likely to have a bigger impact that glomming all your data in a few VBOs (which can make your code more complicated and prone to errors, like you’ve already encountered).

-Won