So I'm trying to make two seperate objects and render them in a rendering loop.
This is the code after the initilization that creates them:
glGenVertexArrays(1, &vaoHandle1); glBindVertexArray(vaoHandle1); glGenBuffers(1, &vertexbuffer1); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer1); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL); glGenBuffers(1, &colorbuffer1); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorbuffer1); glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data),g_color_buffer_data, GL_STATIC_DRAW); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL); glGenVertexArrays(1, &vaoHandle2); glBindVertexArray(vaoHandle2); glGenBuffers(1, &vertexbuffer2); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer2); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data2), g_vertex_buffer_data2, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL); glGenBuffers(1, &colorbuffer2); glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorbuffer2); glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data),g_color_buffer_data, GL_STATIC_DRAW); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL);
For reference here are the actual vertex arrays:
And this is my main rendering loop:
void renderCallback()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programID);
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
glBindVertexArray(vaoHandle1);
glDrawArrays(GL_TRIANGLES, 0, 12*3);
glBindVertexArray(vaoHandle2);
glDrawArrays(GL_TRIANGLES, 0, 12*3);
glBindVertexArray(0);
glutSwapBuffers();
glutPostRedisplay();
frames++;
}
This worked when I was only rendering one object, but after I modifyed it, it screwed everything up.
Unfortunatly there aren't a lot of opengl tutorials out there that deal with versions 3 and 4.
And of those, I haven't found one that explains how to render more than one object (VBO/VAO) in the same program, which is obviously essential.
Edited by Syerjchep, 16 February 2013 - 12:43 PM.






