I'm trying to add colors to my object that using a single struct and single VBO in OpenGL. To do this, I have a Vertex
struct that I created that looks like this:
typedef struct {
float x;
float y;
float z;
float r;
float g;
float b;
float a;
} Vertex;
I already know that I'm setting all of the coordinates and colors correctly to get what I want, because I ran a test iterating over each object I have stored in my list and drawing out the points and setting the colors using glVertex3f
and glColor4f
(this was significantly slower than what I'm looking for). But when I try to draw it using VBOs I just get a huge mess of colored triangles going everywhere.
The part of my rendering loop that draws the VBO looks like this:
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, NULL);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, offsetof(Vertex, r), NULL);
glDrawArrays(GL_TRIANGLES, 0, vertex_amount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
What am I doing wrong?