View Full Version : VBO help needed

04-02-2003, 02:13 AM
Hello everyone,

I played a little bit around with VBO but did not manage to get it working. The specs where a little over my head and my C is not really good. So could anyone tell me what my code should look like to use VBO instead of normal VA?
Actually I render my models like this:

glVertexPointer(3, GL_FLOAT, 0, VertexArray.Data);
glNormalPointer(GL_FLOAT, 0, NormalArray.Data);

VertexArray and NormalArray are global arrays and every Mesh has a Model array that contains the indicies pointing into the above mentioned arrays.

thx for any help

04-02-2003, 04:21 AM

Assuming your data never changes, you may do this :

In the initialization part (or the first time you render) :
GLuint buffers[3];
glGenBuffersARB(3, buffers);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[0]);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, VertexArray.SizeInBytes, VertexArray.Data, STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[1]);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, NormalArray.SizeInBytes, NormalArray.Data, STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[2]);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, Model.SizeInBytes, Model.Data, STATIC_DRAW_ARB);

In the rendering function, every frame :
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[0]);
glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[1]);
glNormalPointer(GL_FLOAT, 0, (GLvoid*)0);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers[2]);

In the destruction part (or the last time you render) :
glDeleteBuffersARB(3, buffers);

04-02-2003, 07:25 AM
Thanks, this looks easy enough for me. But I think (as you stated) this will only work for never changing data, which is true for my Vertex- and Normalarray.
But every mesh has its own model array. Therefor I think I must handle it different than the two never changing arrays, looks like I have to change the data in the 'index buffer' on a per model basis. But I will try to figure this one out myself.
Thanks, again.