Is there a way to force OpenGL credentials to start at one instead of zero?

advertisements

I store OpenGL identifier in variables of the type GLuint. But I do not know to what value I should initialize these variables. I would like to initialize them to zero, but unfortunately that is a valid identifier for OpenGL.

The variables must be initialized before storing the OpenGL objects because that is asynchronously done later. So can I somehow force OpenGL to start indexing with one instead of zero? Or should I use GLint and initialize to -1?

I would like to solve this in a clean way. Of course I could store a pair of the variable and a boolean flag or something like this. But that would be hacky. How do you approach this issue?


I would like to initialize them to zero, but unfortunately that is a valid identifier for OpenGL.

No it isn't. 0 means "not an object" for most OpenGL object types. The only ones that have a valid 0 object are FBOs (where 0 means Default Framebuffer), transform feedback objects, and textures (which you should treat as if they were not objects).

So just use zero. It's legal to call any glDelete* with a zero, and nothing will happen, even if 0 is a valid object for that type.