PDA

View Full Version : Fog problem



Evan Meakyl
09-08-2003, 05:06 AM
Hi

the code is a bit long (near 60 lines) so I prefer first to be sure...: the fog is only influenced by the modelview matrix and the fog parameters, isn't it?

If yes, I have a strange problem!

[This message has been edited by Evan Meakyl (edited 09-08-2003).]

Mazy
09-08-2003, 05:20 AM
as a followup question, you dont put anything else than the projection parameters in the projection matrix do you? no scale, rotate or translate in that one.

Evan Meakyl
09-08-2003, 11:28 AM
Thanks for answering Mazy but no ... Here is what I do ; this is the only OpenGL part of the program (I have try to present it the sexiest way possible ... I think I failed http://www.opengl.org/discussion_boards/ubb/smile.gif ):

bool bTest=false;

void InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
GLfloat fogColor[]={0.35f,0.45f,0.7f,1.0f};

glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.3f, 0.45f, 0.6f, 0.0f); // Blue Background
glClearDepth(1.0f); // Depth Buffer Setup

glFogi(GL_FOG_MODE, GL_EXP); // Fog Mode
glFogfv(GL_FOG_COLOR, fogColor); // Set Fog Color
glFogf(GL_FOG_DENSITY, 0.45f); // How Dense Will The Fog Be

/**** I SET THE MATRIX HERE AND ONLY HERE ****/
glMatrixMode(GL_MODELVIEW);
{
GLfloat f[]={-1.000000f,0.000000f,0.000000f,0.000000f,
0.000000f,0.069829f,0.997559f,0.000000f,
0.000000f,0.997559f,-0.069829f,0.000000f,
0.000000f,-0.179561f,1.015016f,1.000000f};
glLoadMatrixf(f);
}

glMatrixMode(GL_PROJECTION);
{
GLfloat f[]={2.414213f,0.000000f,0.000000f,0.000000f,
0.000000f,2.414213f,0.000000f,0.000000f,
0.000000f,0.000000f,1.010101f,1.000000f,
0.000000f,0.000000f,-1.010101f,0.000000f};
glLoadMatrixf(f);
}

/**** (1) ****/
glEnable(GL_FOG);

glEnableClientState(GL_VERTEX_ARRAY);
}

void DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
GLfloat height=-0.65f;
typedef struct { GLfloat x,y,z; } strVertex;
strVertex first[]={
{-5.0f, 5.0f, height+1.3f}, { 5.0f, 5.0f, height+1.3f}, {-5.0f, -5.0f, height+1.3f},
{-5.0f, -5.0f, height+1.3f}, {5.0f, 5.0f, height+1.3f}, {5.0f, -5.0f, height+1.3f}
};
strVertex second[]={
{-5.0f, 5.0f, height}, { 5.0f, 5.0f, height}, {-5.0f, -5.0f, height},
{-5.0f, -5.0f, height}, { 5.0f, 5.0f, height}, { 5.0f, -5.0f, height}
};

glClear(GL_COLOR_BUFFER_BIT ); // Clear Screen Buffer

/***** (2) ******
if (bTest) {
glDisable(GL_FOG);
glVertexPointer(3,GL_FLOAT, sizeof(strVertex), (GLfloat *)first);
glDrawArrays(GL_TRIANGLES, 0, 6);
}

glEnable(GL_FOG);
glVertexPointer(3,GL_FLOAT, sizeof(strVertex), (GLfloat *)second);
glDrawArrays(GL_TRIANGLES, 0, 6);
}

During the execution, the bTest value is swapped when I put a key, which allow me to draw FIRST a band without fog (2)...

First I have what I should have: a dark blue band in the bottom of the screen [1]. Then I push a key and that's weird: the bottom band become very "bright", and the top band is as totally white as I wanted [2].

And more strange: when I push again a key, there is the bottom band, but it isn't dark blue anymore (it is still bright)... [3]. And I can't come back to [1]!!!

I have made screen capture:
[1] http://florent.cohen.free.fr/scr_cap1.jpg
[2] http://florent.cohen.free.fr/scr_cap2.jpg
[3] http://florent.cohen.free.fr/scr_cap3.jpg

And stranger, when I comment (1), I go directly to [3]...

I thought the correct behaviour would be [1] and a mix between [2] and [1]...

Any idea? I am totally lost!!!

[This message has been edited by Evan Meakyl (edited 09-08-2003).]

Evan Meakyl
09-09-2003, 05:47 AM
OK I have ran my test-program on a GeForce4 and everything went fine...

=> it's (once again) a bug driver for my ATI All In Wonder Radeon.

I will report to ATI.

Thanks!

[This message has been edited by Evan Meakyl (edited 09-09-2003).]

Leyder Dylan
09-10-2003, 12:08 AM
Mort de rire ...