glGenBuffers - basics

Hi Forum,

I am having trouble to create a buffer object . The buffer id is returning 0 . Is this a valid value?

I checked in the funcion reference - glIsBuffer() that it returns false if the buffer id is 0.

I am lost here, i am not aware of the reasons why you might have the buffer id 0 even after calling the function :


Some explanation over this issue would be very helpful, specially where to look into once you have this type of bug.


Id 0 is a reserved object id that means “no object”, for example to not bind any buffer to <target>: glBindBuffer(<target>, 0).
Are you on windows? Are you dynamically loading OpenGL functions for 1.2+ correctly (see the wiki)?

As well as checking you’re loading the functions correctly, are you making the calls in a place where you have a current OpenGL context (ie. not trying to create a buffer object before the context is created, or from the wrong thread).

Although it doesn’t really help in this case, when a function is meant to return a value via a parameter and doesn’t seem to be working correctly sometimes it’s worth changing the default value passed in to see if it always returns the same value or is just leaving the value untouched.

GLuint bufferId = 42;
glGenBuffers(1, &bufferId);

If it returns 0 then it’s setting it to that value, if bufferId remains 42 then the function isn’t adjusting the value. Sometimes the difference between the the value being set or untouched can help identify the problem.

If the function pointers weren’t being loaded I’d expect a crash when attempting to call glGenBuffers rather than return of 0.

A possible cause - and here I’ll freely admit that I’m just pulling ideas off the top of my head - is that you’re actually loading something else in place of glGenBuffers, and that something else has the same function signature, possibly as a result of copy-and-paste code. E.g something like this:

glGenBuffers = (PFNGLGENBUFFERSPROC) wglGetProcAddress ("glDeleteBuffers");

If that was the case, then the following code sequence would be expected to return 0:

GLuint bufferid = 0;
glGenBuffers (1, &bufferid);

Thanks Folks for all the hint. I shall elaborate more on this issue. Basically the problem arose in whiling working with OpenSceneGraph System which uses OpenGL down the pipeline. I am working on Ubuntu Linux with NVIDIA GTX 560M and OSG is dynamically loading the OpenGL functions. I have made sure from the OSG that the application is single-threaded. OSG is loading the OpenGL functions through function pointer and while doing that the application is not crashing.

Is that anything to do with OpenGL context. I am also making the context current.

I am creating an OpenCL plugin for the OpenSceneGraph . OpenSceneGraph already has the CUDA plugin. glGenBuffers() works fine with one of its CUDA example . But it not behaving with the OpenCL attachment that i am trying to create here.