Why don't I need to bind my vertex buffer object before calling glDrawArrays?
Posted
by
valmo
on Stack Overflow
See other posts from Stack Overflow
or by valmo
Published on 2013-11-08T11:52:10Z
Indexed on
2013/11/08
15:54 UTC
Read the original article
Hit count: 206
I'm a bit confused why this still renders. I thought you need to bind a vertex buffer object so that glDrawArrays knows which vertex buffer to use.
Here is my initialisation code..
// Create and bind vertex array to store vertex attribute states.
glGenVertexArraysOES(NUM_VERTEX_ARRAYS, &m_vertexArray);
glBindVertexArrayOES(m_vertexArray);
// Create and bind vertex buffer to store vertex data.
glGenBuffers(NUM_VERTEX_BUFFERS, &m_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * 36, &m_vertices[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(VertexAttribPosition);
glVertexAttribPointer(VertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
glEnableVertexAttribArray(VertexAttribNormal);
glVertexAttribPointer(VertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrayOES(0);
Here is my render code. I'm confused why glDrawArrays still works when I bind 0 to GL_ARRAY_BUFFER.
glBindVertexArrayOES(m_vertexArray);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArrayOES(0);
© Stack Overflow or respective owner