PDA

View Full Version : Everything is fog , when i enable fog



Adrian B
01-09-2011, 03:14 PM
just like the thread`s name says, i don`t understand why , but after i enable fog , my scene isn`t visible anymore , the only thing i see is dense grey fog ...

i use fog in my recently started opengl app , so far i`ve got some models , which i made in 3ds max , and i imported, using the GLM library into my opengl app. my models are a terrain , a skydome and a castle , which are also textured.

i`ve managed to rotate , scale and translate the objects so that every one is at they`re correct place in the scene .

i also can move "the camera" through the scene with W A S D keys and look around with the mouse.

i also defined a simple directional light.

my light code:

GLfloat ambientLight[]={0.1, 0.1,0.1,1.0};
GLfloat diffuseLight[]={0.8,0.8,0.8,1.0};
GLfloat specularLight[]={0.2,0.2,0.2,1.0};
GLfloat lightPos[]={1.0 , 1.0 , 1.0 , 0.0};
GLfloat specularReflection[]={1.0,1.0,1.0,1.0};

glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight);
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);


glMaterialfv(GL_FRONT, GL_SPECULAR, specularReflection);
glMateriali(GL_FRONT,GL_SHININESS,128);

glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glShadeModel(GL_SMOOTH);

my fog code :

GLfloat fogColor[4]= {0.5f, 0.5f, 0.5f, 1.0f};
GLfloat density = 0.3;

glEnable (GL_FOG);
glFogi (GL_FOG_MODE, GL_EXP2);
glFogfv (GL_FOG_COLOR, fogColor);
glFogf (GL_FOG_DENSITY, density);
glHint (GL_FOG_HINT, GL_NICEST);


if anyone has an ideea , please help

i also added pictures

ZbuffeR
01-09-2011, 04:31 PM
First, do you see something with :
glFogf (GL_FOG_DENSITY, 0.0f);

If true, then you may have a problem with model scale.
Try with very low values, such as 0.0000001 : is it any better ? Try 10x etc.

You may have a transformation problem, remember there are different matrix stacks in OpenGL, and doing modelview transformations in GL_PROJECTION matrix (instead of the correct GL_MODELVIEW) can mess the fog.
Search for "fog" in this page :
http://www.opengl.org/resources/faq/technical/viewing.htm

Adrian B
01-09-2011, 04:47 PM
thanks a lot ZbuffeR , by reducing the density to 0.0 made fog invisible , after that i set the density to 0.005 , which made the scene and also the fog visible.

but now the fog is through the whole scene , and i would like to make the fog vizible on the y axis only as high as the terrain , so that the skydome is perfectly visible with no fog , otherwise the fog makes the sun unrecognisible

i tried with :
glFogf(GL_FOG_START, 1.0f);
glFogf(GL_FOG_END, 100.0f);

but that would be the depth ... changed the params. but dindn`t notice any changes

how could i do that ?


also added pix: