Calling glGenLists() from the heap in C++

Sorry if this is an old question, I couldn’t see it any of the other posts.

The problem is this; when I call glGenLists from dynamic memory 0 is returned, from static memory the call succeeds. I’m using C++ and programming a 32-bit win32 API compiler, using new and delete only.

if anyone can shed any light, cheers

Why don’t you show us code so we can see exactly what you are doing wrong. From OpenGL’s perspective (as with any library) it makes absolutely no difference how the memory is allocated, so long as it IS allocated.

Yeah, sorry. Basically, in the constructor function of an object I make a call to glGenLists(). The object is allocated using ‘new’ and all the other intializations within the constructor work. From my main method a simmilar call is made, this succeeds.

Hope this helps, again, if anyone can help, cheers.

Make sure your constructor gets called after creating the OpenGL context and making it current.
You shouldn’t have static allocated objects that make OpenGL calls in the constructor, because this will happen upon loading, which is too early.

Like zeckensack said, you are probably calling your OpenGL calls too soon. Until you have a valid context created with wglCreateContext and made current with wglMakeCurrent, none of your OpenGL calls will work.

Cheers chaps, you where right. Thanks again.