Lights not moving or Fog not moving - This way or that way a problem

I now have a “moving” camera, by moving the world. I want to use lighting and Fog, but my problem is, that when i do the translation in the GL_PROJECTION_MATRIX the fog doesnt move relative to the camera, and when i do it (EVERYTIME!!!) in the GL_MODELVIEW_MATRIX which seems to be more inefficient, cause i have to do it for every object, the lights don’t move with the world. What do i have to do to get a fog moving with the camera and lights being on the same position of the world(relative)?
Thanks for incoming help
new WAIT(FOR_ANSWERS);
Ls

First off, don’t translate the projection matrix. Doing so screws up the fog. You need to translate the modelview matrix to move things. To get your lights to move with the world, you simply need to position them before drawing any of the world, i.e. do not translate the modelview matrix before positioning the lights.

lightsabre,

DFrey is exactly right. Don’t tranform the projection matrix. Be sure to use the modelview matrix, load identity and then begin drawing.

More to the point of your fog problems, I found it best to declare the fog properties and turn it on in the function which declares all the world parameters (some call it setupRC() or init() or somesuch). Like so:

  1. Within setupRC()…
    a. declare light color value definitions
    b. define culling, enable always-on states (like glEnable(GL_CULL_FACE))
    c. enable lighting, and the individual lights, assigning color values from step a.
    d. enable material color if applicable
    e. fetch display list ID’s, texture objects ID’s
    f. define blend function and clear color
    g. define fog properties, including begin and end

  2. Within the main rendering function (we’ll call it renderScene())
    a. clear whatever buffers you are using (color, depth, stencil, accumulation)
    b. declare material properties for objects drawn
    c. position lights
    d. draw whatever you need, using matrix transformations at this point
    e. swap buffers and flush

Notice I didn’t load the projection or model view matrix at any point in either function. Though some may argue this practice, I do the individual loading of these during my resize function. This prevents me from worrying about whether I am transforming while not in the modelview matrix state.
Additionally, note that fog is declared in the setup function once, and it’s good to go. From that point, it should behave as one would expect, beginning where you declare it and fogging linearly or exponentially outwards along modelview z.

Sorry for the length of the post. Looking back, DFrey answered your question fairly succintly. <shrug>

Glossifah