C++ - Opengl VAO and VBO Objects - Stack Overflow
C++ - Opengl VAO and VBO Objects - Stack Overflow
Asked 7 years, 2 months ago Modified 1 year, 3 months ago Viewed 214 times
I want to create multiple vertex buffers in objects (one by object). the constructor is:
{
glGenBuffers(1, &_vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferID);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
//
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(0); //??????
glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferID);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
//
}
If I create 1 object VertexBuffer, this works ok. But if I create another object (I won't use it) and I draw the
first object again the result is not correct (for example, the object showed is in other place). Why?
Share Improve this question Follow edited Jan 11, 2023 at 4:02 asked Jan 15, 2017 at 6:36
genpfault Pavel Angel Mendoza
51.6k 11 88 142 Villafane
417 1 5 21
1 You should show your drawing code too. – Yakov Galka Jan 15, 2017 at 7:46
You don't seem to store the vao anywhere, but you should. Before drawing each object you shall
glBindVertexArray its vao (but not _vertexBufferID ) before you call any of glDraw* .
1
See also this answer to see what state VAOs contain.
Share Improve this answer Follow edited Jan 11, 2023 at 3:43 answered Jan 15, 2017 at 7:43
Yakov Galka
71.6k 16 143 220