dms::Transparency

Source Code

Class Specification

#include <dms/Transparency.h>

Transparency(GLenum source=GL_ONE, GLenum dest=GL_ZERO,
             GLenum func=GL_ALWAYS, GLclampf ref=0.0);
void apply(void);
void disable(void);

void setBlend(GLenum source, GLenum destination);
void setAlphaTest(GLenum func, GLclampf ref);
void setNoBlend(void);
void setNoAlphaTest(void);

static Transparency StandardBlend;
static Transparency AlphaTestZero;

Description

Transparency(GLenum source, GLenum dest, GLenum func, GLclampf ref)

By default, the Transparency constructor creates an object that will perform no transparency - both blending and alpha testing are disabled.
Example:

Transparency alphaGreaterThan25(GL_ONE, GL_ZERO, GL_GREATER, 0.25);
void apply(void)

Applies the selected transparency modes. Enables GL_BLEND if blending is used, and GL_ALPHA_TEST if alpha testing is used.
Example:

Transparency alphaGreaterThan25(GL_ONE, GL_ZERO, GL_GREATER, 0.25);
alphaGreaterThan25.apply();
void disable(void)

Disables whatever transparency modes were enabled by apply(). (Note: if you change a Transparency object's settings while the object is applied, disable() might not function correctly.)
Example:

alphaGreaterThan25.apply();
drawObject();
alphaGreaterThan25.disable();
void setBlend(GLenum source, GLenum destination)

Sets the Transparency object to use blending with the given source and destination factors. The arguments are the same as ones that would be passed to glBlendFunc(). Calling setBlend(GL_ONE, GL_ZERO) will disable blending by the object.
Example:

transp.setBlend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
void setNoBlend(void)

Disables blending by the Transparency object.

void setAlphaTest(GLenum func, GLclampf ref)

Sets the Transparency object to use alpha testing with the given function (func) and reference value (ref). The arguments are the same as ones that would be passed to glAlphaFunc(). Calling setAlphaTest(GL_ALWAYS, ref) will disable alpha testing by the object.
Example:

transp.setAlphaTest(GL_LESS, 0.5);
void setNoAlphaTest(void)

Disables alpha testing by the Transparency object.

static Transparency StandardBlend;
static Transparency AlphaTestZero;

Two predefined constants for typical transparency modes.
StandardBlend uses (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blending.
AlphaTestZero uses (GL_GREATER, 0.0) alpha testing.
Example:

Transparency::StandardBlend.apply();