Open GL Super Bible

Previous Table of Contents Next


Summary

Blending and fog complete the OpenGL library and are yet another source for making the images you generate more realistic. Blending provides transparency effects and improves anti-aliasing of points, lines, and polygons. Fog supports a variety of depth-cueing and weather effects that make images look less exact and, ironically, more like the real world.

Reference Section

glBlendFunc

Purpose
Sets color blending functions.
Include File
<GL/gl.h>
Syntax
void glBlendFunc(GLenum sfactor, GLenum dfactor);
Description
This function sets the source and destination blending factors for color blending. You must call glEnable(GL_BLEND) to enable color blending. Blending is only available in RGBA drawing contexts. The default settings for blending are glBlendFunc(GL_ONE, GL_ZERO).

Parameters

sfactor
GLenum: The source colorís blending function.
dfactor
GLenum: The destination pixel colorís blending function.
Returns
None.
Example
See the example in CH16\BLENDPOT.C on the CD.

glFog

Purpose
Specifies fog parameters.
Include File
<GL/gl.h>
Syntax
void glFogf(GLenum pname, GLfloat param);
void glFogfv(GLenum pname, GLfloat *params);
void glFogi(GLenum pname, GLint param);
void glFogiv(GLenum pname, GLint *params);
Description
The glFog functions set fog parameters. To draw using fog you must call glEnable(GL_FOG).

Parameters

pname
GLenum: The parameter to set. Valid names are as follows:
GL_FOG_COLOR The color of the fog; must be an array of 4 numbers representing the RGBA color.
GL_FOG_DENSITY The fog density; a number greater than 0.0. The density is only used for the GL_EXP and GL_EXP2 fog modes.
GL_FOG_END The farthest distance to which the fog is applied. This is a transformed Z (depth) value from 0.0 to 1.0.
GL_FOG_MODE The fog type; specifies the formula used to render fog effects (GL_LINEAR, GL_EXP, or GL_EXP2).
GL_FOG_START The closest distance to which fog is applied. This is a transformed Z (depth) value from 0.0 to 1.0.
param
GLfloat, GLint: The parameter value.
params
GLfloat *, GLint *: A pointer to the parameter array.
Returns
None.
Example
See the example in CH16\FOGSCENE.C on the CD.


Previous Table of Contents Next