glBlendEquation
Chooses how the two blended terms are combined: added (default), subtracted, or the minimum or maximum.
Signature
void glBlendEquation(GLenum mode);
How it works
glBlendFunc picks the two factors; this picks the operation between the two products. With S = source × sfactor and D = destination × dfactor:
GL_FUNC_ADD: S + D GL_FUNC_SUBTRACT: S − D GL_FUNC_REVERSE_SUBTRACT: D − S GL_MIN / GL_MAX: the smaller or larger of source and destination, channel by channel (the factors are ignored).
Results are clamped to [0, 1] in a normal 8-bit framebuffer.
Parameters
The operation.
Common values
- GL_FUNC_ADD
- Add (default): transparency, additive glow.
- GL_FUNC_REVERSE_SUBTRACT
- Stored minus new: darken what is behind (shadows painted on top, ink).
- GL_FUNC_SUBTRACT
- New minus stored.
- GL_MIN / GL_MAX
- Keep the darker or brighter value per channel.
Tips & pitfalls
The equation stays set: return to GL_FUNC_ADD after a special pass, or later transparent objects blend strangely.
glBlendEquationSeparate takes one mode for colour and one for alpha.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_ENUM
- mode is not one of the five operations.
Example
1glBlendFunc(GL_ONE, GL_ONE);
2glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); // darken
3drawDarkDecal();
4glBlendEquation(GL_FUNC_ADD); // back to normal