Good day. I am trying to make a volumetric fog in OpenGL using glFogCoordfEXT. Why does a fog affect to all object of my scene, even if they're not in fog's volume? And these objects become evenly gray as a fog itself. Here is a pic
Code:
void CFog::init()
{
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, this->color);
glFogf(GL_FOG_START, 0.0f);
glFogf(GL_FOG_END, 1.0f);
glHint(GL_FOG_HINT, GL_NICEST);
glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
}
void CFog::draw()
{
glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);
glEnable(GL_BLEND);
glPushMatrix();
glTranslatef(this->coords[0], this->coords[1], this->coords[2]);
if(this->angle[0] != 0.0f)
glRotatef(this->angle[0], 1.0f, 0.0f, 0.0f);
if(this->angle[1] != 0.0f)
glRotatef(this->angle[1], 0.0f, 1.0f, 0.0f);
if(this->angle[2] != 0.0f)
glRotatef(this->angle[2], 0.0f, 0.0f, 1.0f);
glScalef(this->size, this->size, this->size);
GLfloat one = 1.0f;
GLfloat zero = 0.0f;
glColor4f(0.0, 0.0, 0.0, 0.5);
glBegin(GL_QUADS); // Back Wall
glFogCoordfEXT( one); glVertex3f(-2.5f,-2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f( 2.5f,-2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f( 2.5f, 2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f(-2.5f, 2.5f,-15.0f);
glEnd();
GLenum err;
if((err = glGetError()) != GL_NO_ERROR)
{
char * str = (char *)glGetString(err);
}
glBegin(GL_QUADS); // Floor
glFogCoordfEXT( one); glVertex3f(-2.5f,-2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f( 2.5f,-2.5f,-15.0f);
glFogCoordfEXT( zero); glVertex3f( 2.5f,-2.5f, 15.0f);
glFogCoordfEXT( zero); glVertex3f(-2.5f,-2.5f, 15.0f);
glEnd();
glBegin(GL_QUADS); // Roof
glFogCoordfEXT( one); glVertex3f(-2.5f, 2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f( 2.5f, 2.5f,-15.0f);
glFogCoordfEXT( zero); glVertex3f( 2.5f, 2.5f, 15.0f);
glFogCoordfEXT( zero); glVertex3f(-2.5f, 2.5f, 15.0f);
glEnd();
glBegin(GL_QUADS); // Right Wall
glFogCoordfEXT( zero); glVertex3f( 2.5f,-2.5f, 15.0f);
glFogCoordfEXT( zero); glVertex3f( 2.5f, 2.5f, 15.0f);
glFogCoordfEXT( one); glVertex3f( 2.5f, 2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f( 2.5f,-2.5f,-15.0f);
glEnd();
glBegin(GL_QUADS); // Left Wall
glFogCoordfEXT( zero); glVertex3f(-2.5f,-2.5f, 15.0f);
glFogCoordfEXT( zero); glVertex3f(-2.5f, 2.5f, 15.0f);
glFogCoordfEXT( one); glVertex3f(-2.5f, 2.5f,-15.0f);
glFogCoordfEXT( one); glVertex3f(-2.5f,-2.5f,-15.0f);
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
//glDisable(GL_FOG);
}