• Advertisement
Sign in to follow this  

VBO Question

This topic is 4481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been trying to implement VBO's but I can't seem to get it to work. I've gone over the tutorials and can't see what's wrong. To initialize the VBO, I do the following glGenBuffersARB(1, &mVertsBuf); glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVertsBuf); glBufferDataARB(GL_ARRAY_BUFFER_ARB, (MAX_VERTS) * sizeof(float), mVertices, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); I also have a color array and an indicies array. I do basically the same thing for the color array. I don't bother setting the indicies array to the VBO beacause it's fairly trivial. I draw by doing the following. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); FillData();// fills the member arrays with data to draw glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVertsBuf); glVertexPointer(2, GL_FLOAT, 0, NULL); glBindBufferARB(GL_ARRAY_BUFFER_ARB, mColors); glColorPointer(3, GL_UNSIGNED_BYTE, 0, NULL ); glDrawElements( GL_TRIANGLE_STRIP, DrawVertices, GL_UNSIGNED_SHORT, mIndicies); //indicies not in VBO I don't see what's wrong. I check to make sure my video card supports VBO, and it does. I know the basic drawing routine is OK because when I disable VBO and replace glVertexPointer with member arrays names instead of NULL, it draws fine. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
What exactly do you do in //FillData()? OpenGL will draw what's in the VBO (which you put there with glBufferDataARB, not what's in the arrays.

Share this post


Link to post
Share on other sites
More specifically, after you fill in the data, you need to re-bind the VBO, and call glBufferDataARB() again, to update the VBO with the newly filled in data.

Share this post


Link to post
Share on other sites
It worked when I added the glBufferDataARB after the filling the vertices array. However, I found it to be slower as I expected. The over-head of constantly sending the vertices to my video card slowed the whole process down. It was 3x quicker when I simply left the data local and called glVertexPointer with my member arrays as params. Thanks for all the help. I should have noticed it before.

Share this post


Link to post
Share on other sites
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (MAX_VERTS) * sizeof(float), mVertices, GL_STATIC_DRAW_ARB);

if its a vert than shouldnt this be three floats?
something like MAX_VERTS*(sizeof(float)*3)

Share this post


Link to post
Share on other sites
I agree with Ted. It may not be your main problem, but each vertex is 3 floats. You're only allocating space for 1/3 of your geometry.

Share this post


Link to post
Share on other sites
Keep track of the vertex count and size the vertex buffer accordingly, instead of MAX_VERTS.

Share this post


Link to post
Share on other sites
It's a good idea to use formats that are typically accelerated by GPUs.

For example :
3 floats per vertex
4 ubyte per color


Most importantly, don't call glBindBuffer when you don't have to. That will reduce performance on some cards.

Also, interlace your data. Make 1 VBO that contains the vertex and colors.

Do you really have static data, or is it dynamic?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement