Catman
11-20-2001, 02: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?
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?