Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Thethuthinang

macrumors member
Original poster
Jan 3, 2011
39
0
Hi, I am trying to create a display list in openGL and cannot figure out why it is not working. To trouble-shoot the problem, I have put the code for the display list inside "initWithFrame":

Code:
GLuint theCube;
theCube = glGenLists(1);
glNewList(theCube, GL_COMPILE);
(more code)
glEndList();

I have inserted code with the function "glIsList()" to test whether the list was created. This function should return GL_TRUE if it is called after the line:

Code:
theCube = glGenLists(1);

It does not. I have used basically the same code in a non-cocoa context with success. The major difference between that code and this is the objective-C environment and the way in which the view was initiated. Here, I initiated the view with the code:

Code:
NSOpenGLPixelFormatAttribute attrs[] = {
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 16, 0
};
NSOpenGLPixelFormat* pixFmt = [[[NSOpenGLPixelFormat alloc] initWithAttributes: attrs] autorelease];
self = [super initWithFrame: frameRect pixelFormat: pixFmt];
return self;

inserted inside "initWithRect". Is there something about my initialization that does not enable display lists to be made?
 
You may be calling OpenGL functions before you have an OpenGL context. Try putting the following line before the call to glGenLists.

Code:
NSOpenGLContext *ctx = [self openGLContext];

The OpenGLContext is lazyily initialized, so the first call to openGLContext will create it.

This is assuming the block of OpenGL functions is after the call to super's initWithFrame: pixelFormat:. You can't/shouldn't be doing anything before this call. (And checking it doesn't return nil).

You may also have to move the code from initWithFrame: to awakeFromNib depending on how you're creating your NSOpenGLView-subclass object. If you're doing it by calling initWithFrame: somewhere else in your code, it will be fine. If you doing it via Interface Builder, it will have to be moved.
 
I put the list code in "awakeFromNib", but the list was still not generated (so I guess the openGL context was not created by the time it was called). So, I used "[self openGLContext]" and now the list is recognized (does this mean that calling the "openGLContext" method forced the finalization of the initialization?)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.