glGenBuffers
Reserves names (IDs) for new buffer objects.
Part of the family glGen*
Signature
void glGenBuffers(GLsizei n, GLuint *buffers);
How it works
A buffer object is a block of memory owned by the GPU driver. glGenBuffers does not allocate that memory yet — it only hands you unused integer IDs that you will later use to refer to buffers.
The buffer only really comes into existence the first time you bind the ID with glBindBuffer. Think of it as taking a numbered ticket: the number is yours, but nothing is stored under it until you use it.
Parameters
How many IDs to generate.
Pointer to an array with room for n values; the IDs are written here.
Tips & pitfalls
ID 0 is never returned — it is reserved to mean "no buffer".
In OpenGL 4.5+ prefer
glCreateBuffers, which creates the object immediately without needing a bind.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_VALUE
- n is negative.
Example
1GLuint vbo;
2glGenBuffers(1, &vbo); // just an ID for now
3glBindBuffer(GL_ARRAY_BUFFER, vbo); // now the buffer exists