- 1). Draw a new window device using the GLUT toolkit. Inside the "main() {...}" loop, begin by passing the commands "glutInit();" and "glutInitDisplayMode(...);" where glutInitDisplayMode will take arguments to define settings such as color depth or frame buffering.
- 2). Use "glutInitWindowSize(x,y);" to define the windows size and rendering resolution, and "glutInitWindowPosition(x,y);" to set the point where the left uppermost pixel should begin drawing, using x,y arguments to represent pixel co-ordinates. Display the window and begin rendering with the command "glutCreateWindow();."
- 3). Enable the use of fog and depth testing with the expression "glEnable(GL_FOG | GL_DEPTH_TEST);." Drawing volumetric fog is only possible through the use of the OpenGL extension glFogCoordfEXT and may not be available to your render target. The use of glGetString(GL_EXTENSIONS) and strstr() will allow you to search the OpenGL extension list of the current rendering device, and is recommended if you are deploying to a mobile device.
- 4). Specify how the fog will be rendered into the 3d world. Use "glFogi(GL_FOG_MODE, ...);" to set how the fog will fade as it gets closer to the camera, "glFogfv(GL_FOG_COLOR, ...);" to change the color from the default gray, finally using "glFogf(GL_FOG_START, ... )" and "glFogf(GL_FOG_END, ...);" to modify where the fog will be least and most dense.
- 5). Build the code into an executable file and run it to see how the fog renders to the world. From here you may continue to use the fog effect in a proper project in its current state; however, it will not produce the volumetric effect as it will appear solid. Volumetric fog must be directly applied to a 3d mesh, much like a texture or a shader.
- 6). Use the "glFogCoordfEXT();" function alongside "glVertex3f();" calls when rendering a vertex to the viewpoint, turning the solid fog effect from before into an atmospheric fog with depth.
previous post
next post