GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(0);
vbo.bind(GL_ARRAY_BUFFER);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDisableVertexAttribArray(0);
ibo.bind(GL_ELEMENT_ARRAY_BUFFER); //where do I put this?
glBindVertexArray(0);
while (glfwGetWindowParam(GLFW_OPENED)) {
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
glfwSwapBuffers();
}
The way I understand VAO is that I create a vao handle and bind it like this
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
Now I can fill it the VAO with these three commands
vbo.bind(GL_ARRAY_BUFFER);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glDisableVertexAttribArray(0);
I should note that I used my own vbo class here.
And then I close my VAO with
glBindVertexArray(0);
And then I can just load it in the renderloop
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
But I don't get any output.
Now I think it has something to do with my indexed array. (ibo) How do I use a VAO with an IBO?
A VAO encapuslates the vertex array pointers (including the array buffer bindings at the time of the pointer call), the enable bits and the current GL_ELEMENT_ARRAY_BUFFER
binding (but not the current GL_ARRAY_BUFFER
binding). So the IBO bind that you do is fine at that particular position.
However, you do a glDisableVertexAttribArray( 0 );
while the VAO is still bound, so the VAO contains that attrib array as disabled.