You are not transferring all your data into the vertex buffer. The 2nd parameter of glBufferData
takes the size of all of your vertex data in bytes. You should set it to sizeof(vertex) * vertex_count
.
Also, calling glEnableVertexAttribArray
and glVertexAttribPointer
in loadBufferData
is redundant. You should call them only in your rendering function.
Your second problem is with glVertexAttribPointer
. You are not passing the correct offset to your vertex position data in your vertex data "structure". Since your vertices only consist of positions, this offset should be 0
. If you would have positions and colors for each vertex, these offset could be 0
(for position) and sizeof(float) * 3
(for color, because you have 3 coordinates).
Finally, you only draw a single vertex. You should draw 72/3=24
if your cube has 24
vertices.
I think you can make your life easier by defining an actual structure for your vertices, like so:
struct Vertex
{
float position[3];
};
Then, you can compute offsets for each of your vertex positions, colors, etc, with (GLvoid*)(&((Vertex*)NULL)->position)
.