I am trying to create a simple scene with fog. Forgive my basic trees! My problem is that the fog does not start out thin at the camera position and get denser as you go deeper into the scene. Instead my scene seems to consist of a bubble of clearness with thicker fog inside and outside the bubble. The only thing I know for sure is the zone of clearness passes through the glLoadIdentity() 0,0,0 point. What am I doing wrong?
private void setCameraWithFog(GL2 gl, GLU glu, float x, float y, float z,
float lookingAtX, float lookingAtY, float lookingAtZ) {
gl.glTranslatef(x, y, z);
gl.glEnable(GL2.GL_FOG);
gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_EXP2);
float[] fogColor = {0.5f, 0.5f, 0.5f, 1.0f};
gl.glFogfv(GL2.GL_FOG_COLOR, fogColor, 0);
gl.glFogf(GL2.GL_FOG_DENSITY, 0.3f);
gl.glHint(GL2.GL_FOG_HINT, GL.GL_DONT_CARE);
gl.glFogf(GL2.GL_FOG_START, 0.0f);
gl.glFogf(GL2.GL_FOG_END, 35.0f);
gl.glLoadIdentity();
setCamera(gl, glu, x, y, z, lookingAtX, lookingAtY, lookingAtZ);
}
As you can see I try to set the 0,0,0 point to the eventual camera position before enabling fog but the fog still behaves strangely. Also, which parts of the fog code should be in my init function? I will try to upload a picture when i figure out how.
http://farm8.staticflickr.com/7220/7321892300_6b943d3d86_n.jpg
fogWrong by Agnes.Clarke.01, on Flickr