vertex_buffer_object

Hello,I’m trying to use this extension…mhh…but it doesn’t work correctly!!

Here’s my code:
//-------------------------------------------------------
// Indexes Buffer Allocation !!
for(int i=0 ; i< Scene.NObj ; i++)
{
Size = SINT*Scene.Obj.NVertex;
glBindBufferARB( ELEMENT_ARRAY_BUFFER_ARB, Scene.Obj[i].IBuffer);
glBufferDataARB( ELEMENT_ARRAY_BUFFER_ARB, Size, Scene.Obj[i].Triangle, GL_STATIC_DRAW_ARB);
}

Size = sizeof(_Vertex)*(Scene.NVertex);
glBindBufferARB( ARRAY_BUFFER_ARB, Scene.VBOBuffer);
glBufferDataARB( ARRAY_BUFFER_ARB, Size, Scene.VBuffer, GL_STATIC_DRAW_ARB);

//--------------------------------------------------------
glTexCoordPointer(2,GL_FLOAT,sizeof(_Vertex),&Scene.VBuffer[0].UV );
glNormalPointer(GL_FLOAT,sizeof(_Vertex),&Scene.VBuffer[0].Normal);
glVertexPointer(3,GL_FLOAT,sizeof(_Vertex),&Scene.VBuffer[0].Coord );
glColorPointer(4,GL_FLOAT,sizeof(_Vertex),&Scene.VBuffer[0].Color );
glEnableClientState ( GL_VERTEX_ARRAY );
glEnableClientState ( GL_NORMAL_ARRAY );
glEnableClientState ( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );

//…and render…
glDrawArrays( GL_TRIANGLES, 0, O.NVertex );

All I can see It’s just a mixture o texture and triangle in random position.
If I render the same scene using standard Vertex Array (…commenting the first part of the code) all works correctly.
Standard vertex array:http://utenti.lycos.it/frenz1979/std.jpg
Same scene with buggy VBO:http://utenti.lycos.it/frenz1979/vbo.jpg

Some help?

Moreover…in the extension documentation a find the definition of the function “GenBuffersARB”…but there’s no example of it…is it useless!!!

Thanks to all!!

GenBuffers works just like GenTextures.

BTW, read the example usage in the VBO spec, and pay VERY close attention to the use of the BUFFER_OFFSET macro.

#define BUFFER_OFFSET(i) ((char *)NULL + (i))
…mmhh…seems clear…it’s JUST the offest…

:-(…btw I’ve all the night to think about it…

thanks…

Now it works!!!
Here’s the correct code :slight_smile:

int Size;
Size = sizeof(_Vertex)*(Scene.NVertex);
glGenBuffersARB( 1 , &Scene.VBOBuffer );
glBindBufferARB( ARRAY_BUFFER_ARB, Scene.VBOBuffer );
glBufferDataARB( ARRAY_BUFFER_ARB, Size, &Scene.VBuffer[0], STATIC_DRAW_ARB );

glTexCoordPointer( 2, GL_FLOAT, sizeof(_Vertex), (char*)(0) );
glNormalPointer ( GL_FLOAT, sizeof(_Vertex), (char*)(SFLOAT2) );
glVertexPointer ( 3, GL_FLOAT, sizeof(_Vertex), (char
)(SFLOAT5) );
glColorPointer ( 4, GL_FLOAT, sizeof(_Vertex), (char
)(SFLOAT*8) );

// Indexes Buffer Allocation !!
for(int i=0 ; i< Scene.NObj ; i++)
{
Size = SINT*Scene.Obj[i].NVertex;
glGenBuffersARB( 1 , &Scene.Obj[i].IBuffer );
glBindBufferARB( ELEMENT_ARRAY_BUFFER_ARB, Scene.Obj[i].IBuffer );
glBufferDataARB( ELEMENT_ARRAY_BUFFER_ARB, Size, &Scene.Obj[i].Triangle[0].Edge[0], STATIC_DRAW_ARB );
}


//Draw

glBindBufferARB( ELEMENT_ARRAY_BUFFER_ARB, O.IBuffer);
glBindBufferARB( ARRAY_BUFFER_ARB, Scene.VBOBuffer );
glDrawElements ( GL_TRIANGLES, O.NVertex, GL_UNSIGNED_INT, (char*)(0) );

THANK YOU!!! :-)))