Fog not on the right axis

Hello, I want to implement some fog in my application.

Basically, my scene is rotated by 35 degrees on x and -40 on y (using rotations whine in GL_PROJECTION matrix mode, not with glu_lookat)

I enabled fog, and it shows itself rotated by -40 degrees on y (hence parallel to the Z axis of my modelview matrix, but i’d want it to be perpenticular to the Z axis on the projection.)

here are some ascii sketches
Actual :
fog layer
->/
/\
/ \
/ \ \ <-

Desired :
fog layer
–>/
->/__
/
/ \

I’m guessing you ignored all advice regarding using things like the following on the PROJECTION matrix: gluLookAt, glTranslate, glRotate, glScale.

In case you haven’t been given advice regarding the above, the advice is don’t use those on the PROJECTION matrix. The ONLY things that belong on the PROJECTION matrix are things like glFrustum, gluProjection, glOrtho, and gluOrtho2D. Anything else and you will mess up fog and lighting calculations. The other stuff belongs on the MODELVIEW matrix.

“I’m guessing you ignored all advice regarding using things like the following on the PROJECTION matrix: gluLookAt, glTranslate, glRotate, glScale.”

What advice? Well now I know too, I never realized that putting transforms in the camera matrix could mess up the fog. I had this same problem on an old program. Fog initialized nicely, but as you turned it stayed still so it was like being stuck in a hallway of no fog in a sea of fog.

Falls off his chair, anime-style

My my my. Thank you for this one useful piece of advice! now not only my fog renders correctly, but lightning makes all more sense, and I’ll most likely be able to strip down some pieces of code to push my app one bit faster!

You are a lifesaver, thanks!
(what’s nice, too, is that I simply moved those few translate() and rotate() right after my glMatrixMode(GL_MODELVIEW) without changing anything else, and everything worked A1)
p.s. I didn’t use gluLookAt