juztcode
juztcode

Reputation: 1355

Understanding binding in OpenGL?

I've come across this piece of code in OpenGL:

glGenVertexArrays(GLsizei n, GLuint *arrays);
glBindVertexArray(GLuint array);  

The first line as stated in the doc: returns n vertex array object names in arrays and the second line: binds the vertex array object with name array.

I can only guess that here bind and return in mean different but, these functions sound as if they're doing the same thing. What is it that this term bind refer to and what function does it do different from glGenVertexArrays()?

Upvotes: 0

Views: 477

Answers (2)

metal
metal

Reputation: 6332

glGenVertexArrays() is akin to malloc() or new in that it allocates resources (here, the IDs for Vertex Array Objects or VAOs) that you can use later.

glBindVertexArray() controls which VAO is active -- part of the OpenGL global state. It takes a VAO ID that was allocated by glGenVertexArrays(), creates an underlying OpenGL object for it (if needed), and makes it the current one so that other OpenGL operations apply to it. (It can also de-activate the current VAO.)

More details can be found here.

Upvotes: 1

Peter Lee
Peter Lee

Reputation: 136

glGenVertexArrays() : generated n handles for Vertex Array. handle values are returned arrays

glBindVertexArray() : set a VertexArray active. From now on, you can call opengl API utilizing the vertexArray.

There is many similar API in OpenGL.. bindXXX means make it active.

Upvotes: 2

Related Questions