I'm trying to create terrain from a heightmap in opengl(c++), and following this tutorial.
I'm also trying to use a vertex buffer object to speed it up. In their example, they create a vertex object with 3 floats for x, y, z. They then pass a pointer to an array of these vertex objects to be copied to the buffer object. What I don't understand is why for the size of the buffer parameter they pass it the size of the 3 floats (multiplied by the number of vertices).
Surely the vertex objects being passed to it are larger than just the size of the 3 floats? Does the glBufferDataARB function somehow extract these variables? Is the size of an object equal to the size of the variables in it? or am I missing something?
VBOs store bytes. Later
gl*Pointer()
and/orglVertexAttrib()
calls tell OpenGL how to interpret those bytes.To store three floats you need
sizeof(float) * 3
bytes.To store
N
three-float vertices you needsizeof(float) * 3 * N
bytes.