Function familiesfamily
glGen*
Reserve names (GLuint numbers) for new objects; the object itself appears at the first bind.
Signature
void glGen{Buffers|VertexArrays|Textures|Framebuffers|Renderbuffers|Queries}(GLsizei n, GLuint *ids);
How it works
OpenGL objects are referred to by names: plain unsigned integers. glGen* hands out n unused ones, and 0 always means "no object". A freshly generated name is only reserved: the object is created the first time it is bound (glBindBuffer, glBindTexture…), and only then does it have a type.
That is why a DSA call on a name that was generated but never bound fails. The glCreate* family (GL 4.5) creates real objects at once and is the modern choice.
Reading the name
- Buffers, Textures…
- The kind of object, always plural: the function can make several at once.
- n, ids
- How many names, and the array that receives them (&id for one).
Functions in this family
glGenBuffersReserves names (IDs) for new buffer objects.glGenVertexArraysReserves names (IDs) for new vertex array objects (VAOs).glGenTexturesReserves names (IDs) for new texture objects.glGenFramebuffersReserves names for new framebuffer objects (off-screen render targets).glGenRenderbuffersReserves names for renderbuffers — render-only images you never sample.glGenQueriesReserves names for query objects, which ask the GPU to measure something (time, visible samples).
Example
example.cpp
1GLuint vbo, vao;
2glGenBuffers(1, &vbo); // name reserved
3glGenVertexArrays(1, &vao);
4glBindVertexArray(vao); // VAO created here
5glBindBuffer(GL_ARRAY_BUFFER, vbo); // buffer created here