fogging problems

Hi, I have a program with a flat textured surface you can move around on. I wanted to put fog in my program, but when i do my surface turns the color of my fog and I can’t see what is on it. Is there in extra command I need to put into my code to keep this from happening? Here is the code I use for my fog.

float fogColor[4] = {1,1,1,1};

glFogi (GL_FOG_MODE, GL_LINEAR);//I've also tried GL_EXP and  GL_EXP2
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, 0.1);
glHint(GL_FOG_HINT, GL_DONT_CARE);//I've also tried GL_NICEST
glFogf(GL_FOG_START, 1);
glFogf(GL_FOG_END, 200);//I'v also tried 2 and 5

any help is greatly appreciated

Looks like you’re getting a fog-out :-). Make sure your fog end is in line with your zFar and the scene scaling.

With linear fog, start and end determine the eye space distances for the fog start (no fog) and fog end (all fog), respectively. How this distance is computed is implementation dependent, but a simple eye-space z is not uncommon, which creates a view dependency that you don’t have with radial fog.

Ok, i’ve modified my program to this

	//set and enable fog settings
		float fogColor[4] = {1,1,1,0};

		glFogi(GL_FOG_MODE, GL_EXP2);
		glFogfv(GL_FOG_COLOR, fogColor);
		glFogf(GL_FOG_DENSITY, 0.01);
		glFogf(GL_FOG_START, 2);
		glFogf(GL_FOG_END, 500);

I still get the same problem no matter what type of fog I use. I’m kinda new to fogging so I’m not sure what type of fog I want to use either. I use the following code to prepare to draw the 3D parts of my game

	gluPerspective(60, WX/WY, 1, 500);
	gluLookAt(vehicle.x,vehicle.y,5, vehicle.x +(-cos(vehicle.dir+(3.1415/2)+vehicle.steer*10)*10), vehicle.y +(sin(vehicle.dir+(3.1415/2)+vehicle.steer*10)*10), 1+(mousepos.y/20), 0, 0, 1);

vehicle is a structure variable that holds information about where my camera is and where it’s pointing. mousepos is a variable that holds where my cursor is located on the screen.

Again any and all help is greatly appreciated

For fog mode GL_EXP and gl_EXP2, only GL_FOG_DENSITY is relevant. GL_FOG_START and GL_FOG_END are ignored.

For GL_LINEAR, only GL_FOG_START and GL_FOG_END are relevant. GL_FOG_DENSITY is ignored in this case.

Generally i find linear fog much better controllable than exponential fog.

The following snippet should produce useful results:

  glFogfv(GL_FOG_COLOR, fogColor);
  glFogf(GL_FOG_START, 100); // change this to whatever looks good for your purpose
  glFogf(GL_FOG_END, 480);   // fade out slightly before zFar to avoid popping

I’ve plugged your code into my program yet I still get the same program. I think it would be much easier for you guys if I gave you my entire code so you can test it, so here is the code . I program using glut so I have include a “glut files” folder where all the files need to run and compile my program are located, also in that folder is a text document named “placement” read that if you don’t know where to put the files (glut.h and glut.lib must be placed) I hope this will help determine the problem.

I deeply appreciate your help with this problem.