Skip to main content
gamedev.net
🔒 Locked

vertex_buffer_object

Started by Frenz May 19, 2003 at 3:26 PM 6 replies 750+ views
Original Post
Frenz
Frenz
I''m trying to use this extension..mhh...but it doesn''t work correctly!! 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. 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!!
Brian Jones
Brian Jones
I can''t answer the question about the geometry not being display properly, since I haven''t had a chance to try out the extension (I''m working on a simple project that uses it now).

But for you question about glGenBuffersARB. It''s similar to glGenTextures. You don''t NEED to use it for buffer id''s but it''s best you do.
I don't have a signature
Basiror
Basiror
i miss the hungarian notation


http://www.8ung.at/basiror/theironcross.html
Trienco
Trienco
i wonder where this obsession comes from. its like stopping cars just to tell them that youre missing their car being blue.

where exactly would the code above profit from it or be that much more readable to justify ugly long prefixes that are making it a pain to write AND read?
f@dzhttp://festini.device-zero.de
Frenz
Frenz
However hungarian or not ...here 2 screenshots:

VBO: http://utenti.lycos.it/frenz1979/vbo.jpg
Vertex Array: http://utenti.lycos.it/frenz1979/std.jpg
Ingenu
Ingenu
Did you looked at the examples in the end of the specs ?
Do you use genBuffer function ?

I think you need to have one memory chunk (contiguous memory) for the whole buffer, not one array/memory chunk per ARRAY like you do with vertex arrays.

You don't passe pointers to the gl*Pointer call but rather offset inside the buffer (contiguous memory chunk).

That's all I can say for now, I've not tested this extension yet, since only Catalyst 3.4 included it. (released a few days ago, and I've other priorities atm)

-EDIT-
You're using interleaved arrays right ?
That doesn't change my above comments, except you already have one contiguous memory chunk for the buffer
See GenBuffersARB in the doc it's similar to glGenTextures, and I think IT IS REQUIRED.

-* So many things to do, so little time to spend. *-


[edited by - Ingenu on May 20, 2003 1:13:00 PM]

[edited by - Ingenu on May 20, 2003 1:16:52 PM]
-* So many things to do, so little time to spend. *-
Frenz
Frenz
Yes I read the examples in the end of the specs..there''s no use of GenBuffersARB! :-(
I have one big Vertex buffer(contiguous memory chunk with all the scene vertex), and many other index buffer, one for each "Object" in my scene,I''ve done it with ATI VAO and now I''m trying to do with VBO.

If the use of gl*Pointer in VBO is that in standard vertex array the pointers are right...(..the scene is rendered correctly as you can see in the screeshot:-) )
Frenz
Frenz
Now it works!!!
Here''s the correct code :-)

...................

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*)(SFLOAT*2) );
glVertexPointer ( 3, GL_FLOAT, sizeof(_Vertex), (char*)(SFLOAT*5) );
glColorPointer ( 4, GL_FLOAT, sizeof(_Vertex), (char*)(SFLOAT*8) );

// Indexes Buffer Allocation !!
for(int i=0 ; i< Scene.NObj ; i++)
{
Size = SINT*Scene.Obj.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) );

thanks to all!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.