Jump to content
  • Advertisement
Sign in to follow this  
thinhare

lighting effect varies between immediate mode and display list

This topic is 3158 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I wanted to paint some moving cubes, first I used immediate mode painting, the lighting effect was right because I saw the same effect on those object that didn't move. But it was abit slow in immediate mode, so I reimplemented it using display list, although it was then faster, but the lighting effect was different from that on those standing-still objects. In immediate mode method, I simple compute the location and the heading of the objects and painted them using those values. In display list method, I put the object-shape painting in a display list, and each time using glTranslated to translate to the location, and glRotated to rotate to the right heading, then call glCallList. Is there anyone of you who know the reason of the difference in this lighting effect?

Share this post


Link to post
Share on other sites
Advertisement
I can't quite tell from your description, but I'll take a guess:

Setting the position of a light (using glLight and GL_POSITION) first transforms the light position you gave it into camera space (i.e. multiplying it be the modelview matrix), and then stores that. Subsequent changes to the modelview matrix will not affect the position of the light, but prior ones will.

This means that it matters what order you apply these changes in.

Using display lists, you will probably want to set the light positions before you draw any of the objects---don't put the light positioning code inside the display list. If you have enough lights, however, and you want to vary which ones affect which objects (based on proximity, shadows, or whatever), you might need to do some experimenting.

Also, remember that all of the parameters you pass to gl functions while compiling a display list are evaluated only once, at the time of compilation. When you call the display list, it will re-use the values it calculated earlier. Even if you had expressions in the parameters that might evaluate differently, they aren't getting executed/evaluated again when you call the display list. That's where the speed boost comes from.

If neither of these were relevant to your problem, you may need to post code. Be sure to use the [code][/code] or [source][/source] tags.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!