PDA

View Full Version : Fog problem



Catman
11-20-2001, 03:31 AM
Hi! I've got some proglem with fog in opengl...

First I set the projection matrix like this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, (GLfloat)width, 0.0f, (GLfloat)height, 0.0f, 1.0f);


Then I enable fog and set parameters:
GLfloat color[4] = { r/255, g/255, b/255, 1.0f };

glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, S);
glFogf(GL_FOG_END, E);
glFogf(GL_FOG_DENSITY, 0.35f);
glFogfv(GL_FOG_COLOR, color);
glClearColor(r, g, b, 1.0f);


And finally I put some triangles on the screen like this:
zRecip = 1.0f / pPnt->z;
glVertex3f(pPnt->x, pPnt->y, -1.0f + zRecip);

The problem is that fog isn't working well. How should I set START and END to have it work? When I set START to 0.5, END to 0.75 no fog is displayed. If I set START to 1, END to 5 there is fog, but it is - how should I say - static. I mean everything is covered with the same amount of fog no matter how far the vertex is from the camera position.

Is there anyone how could help me?

11-20-2001, 09:15 AM
Sorry I can't tell you the exact solution, but there are 3 different types of fog, (I don't know their names, that's the problem) which need a different amount of processor power. Go to nehe's site (nehe.gamedev.net)and have a look at the fog tutorial ( number 10 or something like that)
Hope this helps.

zed
11-20-2001, 04:55 PM
density doesnt work for linear fog.
start is where the fog starts at in depth values ie up unitil this point fog is 0 and from this point until end it gradually gets thicker.

use this
distance = lengthofvector( verice - camera )
distance will now contain (in units) how far the vertice is away from the camera.
this should give u an idea on what values to use for the start + end numbers of the fog equation

Catman
11-21-2001, 01:54 AM
I've already tried what's on Nehe's page, but it didn't work.

I also tried FOG_EXP, EXP2, but also they didn't work. I donwloaded a sample program, and it worked well. I've set every parameter to what was in the sample, but nothing happened. So I thought it is because I use a different projection matrix.
I don't know what to do...