VBO Question

Started by
10 comments, last by V-man 18 years, 7 months ago
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.
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.
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.
In what way is the code not working? (e.g. crashing, black screen, etc.)
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.
You might want to try changing the usage from GL_STATIC_DRAW to GL_DYNAMIC_DRAW. The former tells the driver that you won't be updating the VBO frequently, so it'll optimize accordingly. Your usage model is consistent with the latter.
Thanks. I tried it out, but it was still slower. Thanks anyways.
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)
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.

-------------------------------Sometimes I ~self();
Because Fathom is calling glVertexPointer(2, GL_FLOAT, 0, NULL) he/she actually has 2 floats per vertex.

This topic is closed to new replies.

Advertisement