I'm a newbie in OpenGL trying to learn VBO. I have two arrays (point0
with 3 points and point1
with 6 points). Suppose I have two separate VBO names and I initialize them:
glGenBuffers(1, &vbo0);
glBindBuffer(GL_ARRAY_BUFFER, vbo0);
glBufferData(GL_ARRAY_BUFFER, sizeof(point0), point0, GL_STATIC_DRAW);
glGenBuffers(1, &vbo1);
glBindBuffer(GL_ARRAY_BUFFER, vbo1);
glBufferData(GL_ARRAY_BUFFER, sizeof(point1), point1, GL_STATIC_DRAW);
In my display function, I have
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw first triangle (point0) in red
glBindBuffer(GL_ARRAY_BUFFER, vbo0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glColor3f(1,0,0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
// draw second and third triangle (point1) in blue
glBindBuffer(GL_ARRAY_BUFFER, vbo1);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 6, GL_FLOAT, GL_FALSE, 0, 0);
glColor3f(0,0,1);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableVertexAttribArray(0);
I was expecting a red triangle from vb
o0 and two blue triangles from vbo1
. But I get a blue triangle from the points in array point0
. Why is that?