PDA

View Full Version : VBO on Nvidia / Linux / bug in driver?



marco_dup1
06-28-2005, 02:24 AM
Hi

I have written a little viewer and don't get the VBOs right. I used a very simular code in a different code and there was no problems.

the init function is:

unsigned int buffers[ 4 ];
glGenBuffersARB( 1, buffers );
_vertex_buffer = buffers[ 0 ];
_normal_buffer = buffers[ 1 ];
_texcoord_buffer = buffers[ 2 ];
_index_buffer = buffers[ 3 ];
// glBindBuffer( GL_ARRAY_BUFFER, _vertex_buffer );
// glBufferData( GL_ARRAY_BUFFER, _vertices.size() * sizeof( float ), &_vertices[ 0 ], GL_STATIC_DRAW );
// glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, _index_buffer );
// glBufferData( GL_ELEMENT_ARRAY_BUFFER, _indices.size() * sizeof( int ), &_indices[ 0 ], GL_STATIC_DRAW );

and the draw function is:

glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );

//glBindBuffer( GL_ARRAY_BUFFER, _vertex_buffer );
glVertexPointer( 3, GL_FLOAT, 0, &_vertices[0]);
glEnable( GL_VERTEX_ARRAY );

//glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, _index_buffer );
glDrawRangeElements( GL_TRIANGLES, 0, _number_of_vertices, _number_of_indices, GL_UNSIGNED_INT, &_indices[ 0 ] );

glPopClientAttrib();

If I uncomment the vbo binding in init function the vertex arrays aren't anymore drawn. I don't understand this because I don't use them. Maybe its a bug.

regards
marco

Relic
06-28-2005, 03:13 AM
Of course you use VBOs when you bind them!
With VBOs you must give byte offsets into bound buffers instead of the address of your vertex data array in system memory. Read the examples in the VBO spec.
Vertex arrays are enabled with glEnableClientState. That it worked with glEnable in your case is due to the legacy GL_EXT_vertex_array extension.

jide
06-28-2005, 03:39 AM
Originally posted by marco:
Hi

unsigned int buffers[ 4 ];
glGenBuffersARB( 1, buffers );
_vertex_buffer = buffers[ 0 ];
_normal_buffer = buffers[ 1 ];
_texcoord_buffer = buffers[ 2 ];
_index_buffer = buffers[ 3 ];
I didn't read all but here is the first mistake at least: GenBuffers expects the number of buffers to generate for the first argument. You give one and use four. How can you expect that to work properly then ?
If it's a typo error, then...

If you didn't already have read the spec, then go and read it. If you did it, then reread it. Another thing would be to read again and again your code if you think you know enough the specs.

Then follow the advises of Relic.

marco_dup1
06-28-2005, 04:18 AM
Sorry I have changed the code very much because a bug with the xrender extension(two days of constant freeze of the xserver). Original it was 4 and I don't know why I have changed it. I read the spec long ago and it seems it was to long. I use glEnable for vertex arrays since the irix days. Thank you for the anwsers of my stupid question but two days of crashs have mellow my brain.

regards
marco