Sign in to follow this  
  • entries
    34
  • comments
    36
  • views
    15497

Lights Updated

Sign in to follow this  
MotionCoil

205 views

Hey

Just a quick update. I was a bit disillusioned in my last post about the lights mainly because they were just not working correctly. I just fixed it and it was too simple. I just had to note this down incase it helps with other people and also to act as a reminder for me to actually read the code I have written.

The thing is, my maps are scaled down defined by a scalar value in the map format (I know, its not a good idea to use scaling but I find it easier). Anyway, having read NBs about normals having to be one unit long otherwise lighting screws up I remembered to add glEnable(GL_NORMALIZE) (The one that requires more computing). This makes sure that the normals are 1 Unit, no matter what. So I did that but the lighting was still mucked up and looked like a normal bulb light over a model village (So the normals were still the same size- See screen shot in previous post- that was diffused on .2 ...no chance that it should illuminate to that level). Anyway, I was looking through the code and couldn't find anything that was wrong.

I left it a day or so. Then I read through the information in 'The Red Book' and scoped out something that might be the root of my problems- the lighting is calculated using the model view matrix. Whats that at the top of rendering each singular entity of geometry? glPushMatrix(). The thing is I was pushing/popping a new model matrix everytime I rendered a primitive but my ModelLighting(int LightType); function was well before I Pushed the matrix which means the lighting was being based on a non-scaled model view matrix and that meant no matter what the lighting would be screwed.

Hazzah! another problem solved.

Lesson of the day- Always read your code and keep track of the times you push/pop matricies.


[Disclaimer- Do not comment on my bad over complex programming style [smile]]

Now I have a whole load of cycles wasted on iterating through the list of lighting in my level every time I render a single primitive. Major optimizing is required! I say again- Major optimizing is required!

[wink]

Anyway, thats how not to program [smile]

Catch you later, dudes
Sign in to follow this  


1 Comment


Recommended Comments

At least you didn't forget a glEnd(), I did once, and I kept coding without trying out the changes I made[crying]. It took me 3 hours to figure out what was wrong when I finally recompiled and tried to play.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now