Problems with glDisplayList

I’m drawing a single polygon with the following code:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glLoadIdentity();
 glTranslated( 100.0, 100.0, -1.5);
 glRotatef( 50.0, 1.0, 0.0, 0.0);
 glRotatef( 10.0, 0.0, 1.0, 0.0);
 glScalef( 0.5, 1.0, 0.9);

  glBegin(GL_POLYGON);
    glColor3f( 1.0,0.0,1.0);
    glVertex3f(  0,  0,  0);
    glVertex3f( Width,  0,  0);
    glVertex3f( Width,  0,  -Height);
    glVertex3f(  0,  0,  -Height);
  glEnd();

==============================================================

Then I try to replace that part of the code for a display list, but It doesn’t work:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glLoadIdentity();
 glTranslated( 100.0, 100.0, -1.5);
 glRotatef( 50.0, 1.0, 0.0, 0.0);
 glRotatef( 10.0, 0.0, 1.0, 0.0);
 glScalef( 0.5, 1.0, 0.9);

 glCallList(ENVIRONMENT_DL);

==============================================================

The display list was created with:

glLoadIdentity();
glNewList(ENVIRONMENT_DL, GL_COMPILE);
   glBegin(GL_POLYGON);
   glColor3f( 1.0,0.0,1.0);
   glVertex3f(  0,  0,  0);
   glVertex3f( Width,  0,  0);
   glVertex3f( Width,  0,  -Height);
   glVertex3f(  0,  0,  -Height);
   glEnd();
glEndList();

Hello!

Are you sure that ENVIRONMENT_DL is valid and empty?

Osku

Yes, I made some tests with glIsList…
The list is empty, I have no other lists also…

is this code I’ve posted rigth?

Try to remove the glLoadIdentity(); from your DL otherwise it won’t be rotated or translated…

Osku

Sorry, it wasn’t inside the DL…

Osku

The code looks fine - are you using glGenLists() to get ENVIRONMENT_DL, or are you just choosing a number?

Chris

[Sorry,Today I study NOAH IV 's question again and find i got a bad understand .I delete this post which seem to be helpless now. Sorry again.]

[This message has been edited by Suvcon (edited 01-26-2001).]

I tried the example above, except that for me everything worked as expected both times… the output from both programs was identical.

Strange as it may sound, it may be your compiler. I have had problems with my compiler “optimizing” my GL code and moving it around a bit. Try compiling the above fragment with optimization turned off and see what you get.

Chris

But,I have test it by my friend who have a geforce 256 ,It do not display correctly.
my card is tnt-II.it also be same.

what about your pc?

and maybe you have a different setting in other part of the project.Do you use glut?

NOAH IV:
It could be a driver bug with GL_POLYGON (which I believe is not in the top list of highlly used primitives…).
Your code looks ok. Change the GL_POLYGON for GL_QUADS and try.

Suvcon:
Not sure if this is too trivial: remember the nature of opengl states. The load identity wont affect the rendering of the first frame, but when the second frame is rendered it will be done with and indentity modelview matrix if you dont set it before each frame.

Thank you everybody for the replies.

Well, it still does not work…
I tried to use the glGenLists() and it returns 0. So, I think 0,1,2,… are all avalable for use with glNewList. Is it right? Then the problem is not here too.

It could be the optimization problem, like chennes said. But I looked for this options and I found nothing related to opengl or graphics. Any ideas?

I will try change GL_POLYGON for GL_QUADS like coco suggested… I 'll let you know if it works.

From MS help on glGenLists
“If range is zero, if there is no group of range contiguous names available, or if any error is generated, then no display lists are generated and zero is returned.”

Means display list IDs are 1-based and glGenLists returns an error in your case.
Make sure your graphics context is current at the time you create your display list, otherwise it will be just nonexistent.

It sounds interresting…

I’ll will check it again when I get home, but I’m quiet sure I read the same info in the help, but it said the function would return -1 for an error and not 0.

If “0” is returned when an error ocurrs, then that’s the problem.
But why it doesn’t work if I have no other DL?

It should be working…
As I know, there is no glEnable(DISPLAY_LISTS)

Since glGenLists returns a GLuint (an UNSIGNED int), it shouldn’t ever return -1. (It would then actually be 0xFFFFFFFF)

I don’t quite understand why you put the glLoadIdentity() after the glBegin/glEnd stuff. If you have some form of display loop (idle function, timer, etc.) after rendering the first time it’s going to reset the matrix. If you’re using a frustum view, it’s obvious that the lines you tried to draw won’t show with an identity matrix because you draw them with the z-value set to 0, and that should be outside of a frustum view. (Don’t ever use 0 for the near plane.)

If you are using something like gluLookAt when you first setup the app, setting the modelview matrix back to the identity is going to get rid of anything you did with that too.

I didn’t put the glLoadIdentity() “after” the glBegin/glEnd.
My code is in the first post at this topic…

And the problem isn’t the glViewport or glOrtho because it works with the code in the first case, but when I replace that for a Call to a DL with exact the same code… it does not work anymore…

Sorry, it was actually referring to Suvcon’s examples for the second two paragraphs. I should have clarified that.

Your problem seems to be that the display list ID isn’t being generated. As Relic said, make sure you’re RC is current at the time you create your DL.

Like relic said the glGenLists returns “0” when an error occurs…

Well, I was calling the GenLists from an event and it was not working. I put the GenLists into my Init method and the DLs were created. (I don’t know if it should be working when I called it from the event, but It wasn’t…)

Ok, so DL were created but I still can’t modify them! I mean, I call a method from another event and this method replace the DL. (calling glNewList with the ID I got from the glGenLists)… but nothing changes.

Is there any rules about where and when can I call the glNewList?

+++++++++++++++++++++++++++++++++++++++++
redbook:
GLuint glGenLists(GLsizei range);
Allocates range number of contiguous, previously unallocated display-list indices. The integer
returned is the index that marks the beginning of a contiguous block of empty display-list indices.
The returned indices are all marked as empty and used, so subsequent calls to glGenLists() don’t
return these indices until they’re deleted. Zero is returned if the requested number of indices isn’t
available, or if range is zero.
Note: Zero is not a valid display-list index.

I know.
Like I said in my last post, I already solved that ( I created the DL ).
But now I can’t update it.

I mean, when I call a method that changes the display list nothing happens.

Note: For change/update the DL I mean call glNewList with the same ID number.

Was the “event” you were creating your DL called before your code to initialize the window? (i.e. before wglCreateContext et. al)

Your window needs to be initialized to use OpenGL before you can use OpenGL calls like glGenLists.

Once created, display lists can’t be modified without recreating the list. It sounds like that’s what you’re trying to do, but if you’re just recreating the list all the time, why not use something like vertex arrays instead?

Without seeing more of your code, I couldn’t really say why your display list doesn’t seem to get recreated correctly for you.