9
OPENGL FOG

Opengl fog

Embed Size (px)

DESCRIPTION

Fog implementation using Opengl library

Citation preview

Page 2: Opengl fog

Fog is used in most games, to help simulate both the size and reality of an area.

For the fog to work well do this: Enable the opengl depth testing, enable the opengl fog, choose the opengl fog mode, choose the opengl fog color, choose the opengl fog density and set how well we want our opengl fog to look. You can also set the starting and ending distances

for the fog.

Page 3: Opengl fog

the density of the fog. I have done it with this: GLfloat density = 0.3; GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0}; The fog colour is written in four parts, they

cover the RGB values Unfortunately I have been unable to find out

what the fourth value does. Next we have the density which sets

how thick our fog is. If you run the application you can see that a

density of 0.3 is quite thick.

Page 4: Opengl fog

After this we enable our fog and set its parameters.

First off we enable the fog. glEnable (GL_FOG); Now we set the fog mode, here i have set it to

GL_EXP2, which is quite nice looking. glFogi (GL_FOG_MODE, GL_EXP2); Here we set the actual colour of our fog. glFogfv (GL_FOG_COLOR, fogColor); Now the density. glFogf (GL_FOG_DENSITY, density);

Page 5: Opengl fog

And here I have set it up to look the nicest. In large projects, this may slow

down you application. glHint (GL_FOG_HINT, GL_NICEST);

Page 6: Opengl fog

Fog Types

they are GL_EXP, GL_EXP2 and GL_LINEAR.

You would use a different fog type depending on how you would like the current part of your opengl application to look.

It is more a trial and error thing, to choose which opengl fog type you want.

But when you get to know them well, you should be able to visualise the way it will look inside your opengl application.

Page 7: Opengl fog

Now in the last one, you will have seen that I used the fog typeGL_EXP2Now this is not the only one. I only chose it because I thinkthat it looks best.

The others include:GL_EXPandGL_LINEAR

So there are 3 in total.

Page 8: Opengl fog

Now with our fogHint. We have 3 options once again.They are:GL_NICESTGL_FASTESTandGL_DONT_CARE

Nicest makes it look better.Fastest makes it look worse, but run better.

Page 9: Opengl fog

Now we are going to take a look at the start and ending positions for the fog.We set the fog starting position with:glFogf (GL_FOG_START, 1);This sets how far into the screen the fog will start.Then the fog ending position is set withglFogf (GL_FOG_END, 10);This will set how far into the screen the fog will end.