PDA

View Full Version : Problems with glDisplayList



NOAH IV
01-22-2001, 06:25 AM
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();

Osku
01-22-2001, 06:33 AM
Hello!

Are you sure that ENVIRONMENT_DL is valid and empty?

Osku

NOAH IV
01-22-2001, 06:36 AM
Yes, I made some tests with glIsList...
The list is empty, I have no other lists also...

is this code I've posted rigth?

Osku
01-22-2001, 08:34 PM
Try to remove the glLoadIdentity(); from your DL otherwise it won't be rotated or translated...

Osku

Osku
01-22-2001, 08:35 PM
Sorry, it wasn't inside the DL...

Osku

chennes
01-23-2001, 05:07 AM
The code looks fine - are you using glGenLists() to get ENVIRONMENT_DL, or are you just choosing a number?

Chris

Suvcon
01-23-2001, 09:36 AM
[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).]

chennes
01-23-2001, 10:03 AM
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

Suvcon
01-24-2001, 01:08 PM
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?

coco
01-24-2001, 09:38 PM
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.

NOAH IV
01-26-2001, 03:04 AM
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. http://www.opengl.org/discussion_boards/ubb/frown.gif

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.

Relic
01-26-2001, 08:07 AM
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.

NOAH IV
01-26-2001, 08:28 AM
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) http://www.opengl.org/discussion_boards/ubb/smile.gif

Deiussum
01-26-2001, 08:47 AM
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.) http://www.opengl.org/discussion_boards/ubb/smile.gif

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.

NOAH IV
01-26-2001, 09:05 AM
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...

Deiussum
01-26-2001, 09:39 AM
Sorry, it was actually referring to Suvcon's examples for the second two paragraphs. I should have clarified that. http://www.opengl.org/discussion_boards/ubb/smile.gif

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.

NOAH IV
01-26-2001, 12:23 PM
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?

Suvcon
01-26-2001, 02:12 PM
+++++++++++++++++++++++++++++++++++++++++
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.

NOAH IV
01-27-2001, 07:30 AM
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.

Deiussum
01-29-2001, 05:52 AM
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.

NOAH IV
01-29-2001, 07:05 AM
> Was the "event" you were creating your DL called before your code to initialize the window? (i.e. before wglCreateContext et. al)

No. The DL creation event ocurrs after the window creation...

>Once created, display lists can't be modified without recreating the list.

Now I'm confused http://www.opengl.org/discussion_boards/ubb/frown.gif. What do you mean with "recreating" the list? Call glNewList or glGenLists again?
Because I'm calling glNewList with the same ID. And nothing happens...

Look, what is going on is that my animation is running too slow. As I already had discused in another topic, I'm just drawing a few QUADS and I can't beliave it's so slow.
That's why I want to use DL. Just to see if it improves the performance.

Any comments are welcome.

Deiussum
01-29-2001, 09:03 AM
By recreating the DL, I mean using glNewList/glEndList again. What about your few quads is changing that makes you recreate the display list? I don't think you'll see much speed up if it's...

a) just a few quads

and

b) you recreate the lists every frame

If you want, you can e-mail me the code to take a look at and I'll see if I can tell what's wrong when I get the time.

NOAH IV
01-29-2001, 10:02 AM
I'm not trying to recreate the DL every frame!

What I'm doing is to create an scene and then run the simulation. During the simulation the environment is the same and there is no need to change the DL.
But if the user change the scene, then the DL need to be recreated before the new simulation starts.

Anyway, I forgot this DL stuff for while. There are many things to be done and since I didn't find a solution I continued the implementation without DL.

But thanks for everybody who tried to help me on this.

Zadkiel
01-29-2001, 11:24 AM
I know this solution is moronically simple but seen as everything else you've done semms ok the problem could be this stupid:
Are you creating the display list prior to initilazing OpenGL. I racked my brains for two weeks on this problem and could have kicked myself .