Jump to content
  • Advertisement
Sign in to follow this  
Nomad3k

Fog, relatively speaking

This topic is 4506 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, can someone tell me why the fog I've implemented seems to be relative to the origin rather than to my camera's location? I'm guessing this is quite a common error for people when they first implement fog, and that you all did this. To enable fog I do the following, very early in the initialisation process: glFogf(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, 5); glFogf(GL_FOG_END, 25); glFogfv(GL_FOG_COLOR, background); glEnable(GL_FOG); Many thanks.

Share this post


Link to post
Share on other sites
Advertisement
You are probably not setting up the model-view and projection matrices correctly. The projection matrix should be used for transforming from view-space to clip-space only, the model-view matrix should be used for everything else.

Share this post


Link to post
Share on other sites
Well thanks for the response. Firstly, I'm using OpenGL with VS2005 C++.

I don't think that I'm getting my projection & model-view matrices mixed up as the fog is setup in the model-view.

I've basically followed NeHe's lesson 16 , but as (ne)he doesn't move the camera it's no problem for (ne)him. Is there some fog call I should be making each time I move the camera?

Share this post


Link to post
Share on other sites
As JohnBolton said, your matrices are likely set up wrong. The projection matrix goes to the projection matrix stack and nowhere else, and the viewport transform goes to the modelview matrix and nowhere else. You're probably putting the viewpoint transform in the projection matrix where it doesn't belong.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nomad3k
I've basically followed NeHe's lesson 16 , but as (ne)he doesn't move the camera it's no problem for (ne)him.


Camera movement should modify the model-view matrix, not the projection matrix. It is a common mistake. The only functions that should modify the projection matrix are glFrustum, gluPerspective, glOrtho, and related functions. In simple cases where the fov, aspect ratio, and near/far plane distances never change, the projection matrix is set up once and never changed.

Share this post


Link to post
Share on other sites
Ah, now I follow you. Sorry but the earlier explanation lost me. ;)

Fog works a treat now. Many thanks.

Share this post


Link to post
Share on other sites
Thanks for the help John. The final solution highlighted that I hadn't really understood a fair bit, especially revolving around glLoadIdentity(), which I was massively overusing. Re-reading some example code pointed out where I was going wrong. The MS VS help files are completely useless for this kind of thing.

I'll let you get back to what you were doing as I'm now one step closer to total domination of the computer game market! ;)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!