I've been trying to understand VBO's and I actually thought that I did, but it seems I still have questions.
I'm loading an OBJ-file to vectors and then use that information to load up buffers of different kinds (normals, texcoords ...).
At the moment I've restricted myself to just vertex positions and the indices of these.
Please let me know if I understand this correctly:
glGenBuffers(1, &vboID[0]); // generates a buffer in slot 0
glBindBuffer(GL_ARRAY_BUFFER, vboID[0]); // binds the buffer as an ARRAY_BUFFER
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*vertices.size(), NULL, GL_STATIC_DRAW); // describes what I want to do with the buffer and the size of it
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*vertices.size(), &vertices[0]); // loads the buffer with data from the vertices vector with starting position 0 in the array
After I've done this, I do the same with the indices but at slot 0:
glGenBuffers(1, &vboID[1]); // generates a buffer in slot 1
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID[1]); // binds the buffer as an ELEMENT_ARRAY_BUFFER
glBufferData(GL_ELEMENT_ARRAY_BUFFER, ((int)(vFaces.size()) * sizeof(float)), &(vFaces.at(0)), GL_STATIC_DRAW); // loads the buffer with data from the vFaces vector with starting position 0 in the array as well as setting the size of the buffer
After that, I try to draw the model with a "glDrawElements" call (after creating an "earth" object):
glDrawElements(GL_TRIANGLES, sizeof(earth.vFaces), GL_UNSIGNED_INT, &earth.vFaces.at(0));
This gives me absolutely nothing.
When I try to activate and use a VAO then the screen flickers, the graphics driver resets and the program crashes.
What is it that I'm not getting?
The questions that I'm thinking of is how do the program know which VBO to use as a reference for the index VBO? And how does it know the difference between a VBO containing vertex positions and one containing, for example normals?
Thanks for taking the time!
Marcus