1
votes

I am trying to make a simple game using OpenGL. I have already modeled 3D scene. Now I want to add some fog to make it look like in horror. I have used this code below

gl.glEnable(GL2.GL_FOG);
gl.glFogi(GL2.GL_FOG_MODE,GL2.GL_LINEAR);
gl.glFogi(GL2.GL_FOG_START,(int)1);
gl.glFogi(GL2.GL_FOG_END,(int)5);

However that just creates a static fog with some random coordinates. How to make It dependent on the camera movement? So the player will only see clearly on the set distance?

1

1 Answers

0
votes

You can find the definition of glFog (and all the other OpenGL commands, even the classic ones) at www.opengl.org. Fog is always calculated according to the distance from the eye / camera / viewpoint coordinates, so you don't need to do anything special.

Be warned that glFog is part of the old classic OpenGL API and may not work reliably on modern 3D systems.