display list generation

honkFactory
Unregistered
 
Post: #1
Howdy
Sometimes glGenLists() returns 0 for no apparent reason. Does anybody know what could cause this? It is not a missing glEnd(), I have made sure. Is there anything else that could prevent flGenLists() from working?
A.W.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #2
Display lists have to fit into texture memory (I think). If you have really long lists, and lots of data (remember verticies + texcoords + colors + etc... can add up real quick) you might be running out of space on your card.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
honkFactory
Unregistered
 
Post: #3
This is the first display list that my program asks for. There is nothing else open that could be hogging memory.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #4
Lets see some code...
Quote this message in a reply
Feanor
Unregistered
 
Post: #5
When you posted this I decided to do some research. My (lame) guess after doing it is that you have confused glGenLists() with glBeginList(), although they aren't that easy to confuse. Alternately, you are trying to do some gl stuff before gl is properly initialized. Try to compile/run a sample app from nehe with display lists and see if that works.
Quote this message in a reply
honkFactory
Unregistered
 
Post: #6
Ok. Some more info is in order. This program is a document based cocoa program. Each document is a window with an NSOpenGLView subclass of my making in it. This NSOpenGLView subclass is accessible from my subclass of NSDocument view an IBOutlet. The view sets up openGL in the following way.
[SOURCECODE]- (id)initWithFrame:(NSRect)frameRect
{

// Init pixel format attribs
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize,
16,
NSOpenGLPFADepthSize,
16,
0
};

// Get pixel format from OpenGL
NSOpenGLPixelFormat* pixFmt;
pixFmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
self = [super initWithFrame:frameRect pixelFormat:pixFmt];

[[self openGLContext] makeCurrentContext];
[self reshape];

glShadeModel( GL_SMOOTH ); // Enable smooth shading
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); // Clear background
glClearDepth( 1.0f ); // Depth buffer setup
// Really nice perspective calculations
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

{//set up lighting
GLfloat LightAmbient[]= { 0.1f, 0.1f, 0.1f, 1.0f };
GLfloat LightDiffuse[]= { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat LightSpecular[]= { 0.05f, 0.05f, 0.05f, 1.0f };
GLfloat LightPosition[]= { 2.0f, 2.0f, 2.0f, 0.0f };

glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, LightSpecular);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
}

lighting=TRUE;

return self;
}

- (void)reshape
{
NSRect sceneBounds;

[ [ self openGLContext ] update ];
sceneBounds = [ self bounds ];
// Reset current viewport
glViewport( 0, 0, sceneBounds.size.width, sceneBounds.size.height );
glMatrixMode( GL_PROJECTION ); // Select the projection matrix
glLoadIdentity(); // and reset it
// Calculate the aspect ratio of the view
gluPerspective( 20.0f, sceneBounds.size.width / sceneBounds.size.height,
0.1f, 100.0f );
glMatrixMode( GL_MODELVIEW ); // Select the modelview matrix
}[/SOURCECODE]

I am positive that this setup works, because if I draw in immediate mode rather than wit the display lists every thing works fine. The actual drawing takes place in drawRect:, a method of NSOpenGLView that I override. (essentually I just posted the previous code to show that the problem is not in the openGL setup.)

Now the display list is actually created in my NSDocument subclass in the method
[SOURCECODE]- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType[/SOURCECODE]
This methods reads in vertex, normal, texture data from a file into a custom class then instructs that class to make a display list. The building of the display list follow the form [SOURCECODE]SurfaceDispList = glGenLists(1);
if(SurfaceDispList!=0)
{
glNewList(SurfaceDispList, GL_COMPILE);
[self drawSurface];// the actual openGL code that draws stuff
glEndList(); }[/SOURCECODE]
I know [self drawSurface] work because it works in immediate mode. And I have triple check all the glBegin and glEnd statement and they all match up, so no trouble there.

There is actually a pattern to how my program does not work. When there is no other document open in my program, glGenLists(1) returns 0, indicating that it could not make me a display list. If there already is a doc open, I can make the display list but when I call the display list nothing appear (even though the exact same code works in immediate mode.) Very mysterious. Maybe I should move the contruction of the display list in the NSOpenGLView subclass, but I do not see why that would make a difference.

Thanks, Alex
Quote this message in a reply
honkFactory
Unregistered
 
Post: #7
OK, I figured it out, kind of. I moved the segment of code that built the display lists from the
[SOURCECODE]- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType[/SOURCECODE]
methos of my NSDocument subclass to the [SOURCECODE]- (void)windowControllerDidLoadNib:(NSWindowController *) aController[/SOURCECODE]
of the same class. I am not sure why this worked. Correct if I am wrong but as I understand it, when a new document is opened from file things happen in this order
1) the NSDomument subclass runs its init method
2) the NSDomument subclass runs either the (BOOL)readFromFile:... method or one of two other methods which load data from a file at a given path.
3) the nib file associate with the NSDocument subclass is instantiated
4) windowControllerDidLoadNib: method is called so that you can finish up your intialization with acces to instances created in interface builder.
I wouldn't be surprised if my understanding of this process is incomplete or straight out wrong. Please set me straight if this is the case.

When I moved my building of the display list from step 2) to step 4) all of a sudden it worked. I don't know why this is the case because the discplay list is not stored in an object declared in step 3). It is stored in an object declared in step 1). Very strange. If you know what is going on please enlighten me.
A.W.
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #8
Generating a display list requires a current OpenGL context. That display context is managed by the document window, which is created when the document nib is opened, which is after the file loading call. If there is no current context, all OpenGL operations fail.
Quote this message in a reply
honkFactory
Unregistered
 
Post: #9
Eureka! The openGL context is an openGLView subclass that is instatiated in step 3), when the nib file is set up. OK. This makes perfect sense. Thanks for explaining it.
A.W.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Vertex buffer generation and rendering iphone eliscool 2 2,695 Dec 17, 2008 05:57 PM
Last Post: ThemsAllTook
  2D Image Generation & openGL LWStrike 2 3,302 Mar 28, 2006 03:34 PM
Last Post: OneSadCookie
  Roots of Display List Overhead aarku 10 5,535 Apr 12, 2005 12:24 PM
Last Post: FCCovett
  Display list overhead TomorrowPlusX 4 4,103 Dec 20, 2004 02:13 PM
Last Post: TomorrowPlusX
  how small is a "small" display list? Diplomtennis 5 3,989 Oct 31, 2004 10:38 AM
Last Post: Hog