Vertex arraysGL 3.0

glBindVertexArray

Makes a VAO current: it records vertex setup calls and is used by draw calls.

Part of the family glBind*

Signature

void glBindVertexArray(GLuint array);

How it works

Binding a VAO has two roles. While you set things up, every glVertexAttribPointer, glEnableVertexAttribArray and GL_ELEMENT_ARRAY_BUFFER bind is recorded into it. When you draw, the GPU reads vertices exactly as the bound VAO describes.

A typical frame is therefore: bind VAO → draw → bind next VAO → draw.

Parameters

arrayGLuint

VAO ID, or 0 to unbind.

Tips & pitfalls

  • Drawing with VAO 0 in the core profile produces GL_INVALID_OPERATION and nothing on screen.

  • Bind the VAO BEFORE binding the element buffer, otherwise the index buffer is not recorded.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_OPERATION
array is not 0 and was never returned by glGenVertexArrays.

Example

example.cpp
1glBindVertexArray(vao);
2glDrawArrays(GL_TRIANGLES, 0, 3);
3glBindVertexArray(0);
Official Khronos documentation