I wrote this "Model" class to load .obj files and distribute data for them in VBO. Its code looks something like this: (note how it does not use VAO)
class Model {...}
void Model::LoadOBJ(const char *file)
{
...
if(glIsBuffer(_vbo) == GL_FALSE)
{
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
}
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * _vec.size(), &_vec[0][0], GL_STATIC_DRAW);
}
void Model::Draw()
{
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glDrawArrays(GL_TRIANGLES, 0, _numVertices);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
I used to think that the following code would work just fine for rendering two different objects:
void init()
{
GLuint VAO;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
Model cube = load("cube.obj");
Model cow = load("cow.obj");
glVertexAttribPointer(prog.GetAttribLocation("vertex"), 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(prog.GetAttribLocation("vertex"));
}
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
...
cube.Draw();
...
cow.Draw()
glutSwapBuffers();
}
but it turns out that OpenGL will just draw two cows or two cubes. (depends on which model is loaded last in init ())


By the way, I’m sure that in the first image opengl tried to draw two cows, but the glDrawArrays () function was called with the number of vertices needed for the cube.So what am I missing? Do I need a different VAO for each buffer object or something like that?