- cpp3ds
- BlendMode
Blending modes for drawing. More...
#include <BlendMode.hpp>
Public Types | |
enum | Factor { Zero, One, SrcColor, OneMinusSrcColor, DstColor, OneMinusDstColor, SrcAlpha, OneMinusSrcAlpha, DstAlpha, OneMinusDstAlpha } |
Enumeration of the blending factors. More... | |
enum | Equation { Add, Subtract } |
Enumeration of the blending equations. More... | |
Public Member Functions | |
BlendMode () | |
Default constructor. More... | |
BlendMode (Factor sourceFactor, Factor destinationFactor, Equation blendEquation=Add) | |
Construct the blend mode given the factors and equation. More... | |
BlendMode (Factor colorSourceFactor, Factor colorDestinationFactor, Equation colorBlendEquation, Factor alphaSourceFactor, Factor alphaDestinationFactor, Equation alphaBlendEquation) | |
Construct the blend mode given the factors and equation. More... | |
Public Attributes | |
Factor | colorSrcFactor |
Source blending factor for the color channels. More... | |
Factor | colorDstFactor |
Destination blending factor for the color channels. More... | |
Equation | colorEquation |
Blending equation for the color channels. More... | |
Factor | alphaSrcFactor |
Source blending factor for the alpha channel. More... | |
Factor | alphaDstFactor |
Destination blending factor for the alpha channel. More... | |
Equation | alphaEquation |
Blending equation for the alpha channel. More... | |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const BlendMode &left, const BlendMode &right) |
Overload of the == operator. More... | |
bool | operator!= (const BlendMode &left, const BlendMode &right) |
Overload of the != operator. More... | |
Blending modes for drawing.
cpp3ds::BlendMode is a class that represents a blend mode.
A blend mode determines how the colors of an object you draw are mixed with the colors that are already in the buffer.
The class is composed of 6 components, each of which has its own public member variable:
The source factor specifies how the pixel you are drawing contributes to the final color. The destination factor specifies how the pixel already drawn in the buffer contributes to the final color.
The color channels RGB (red, green, blue; simply referred to as color) and A (alpha; the transparency) can be treated separately. This separation can be useful for specific blend modes, but most often you won't need it and will simply treat the color as a single unit.
The blend factors and equations correspond to their OpenGL equivalents. In general, the color of the resulting pixel is calculated according to the following formula (src is the color of the source pixel, dst the color of the destination pixel, the other variables correspond to the public members, with the equations being + or - operators):
All factors and colors are represented as floating point numbers between 0 and 1. Where necessary, the result is clamped to fit in that range.
The most common blending modes are defined as constants in the sf namespace:
In SFML, a blend mode can be specified every time you draw a cpp3ds::Drawable object to a render target. It is part of the cpp3ds::RenderStates compound that is passed to the member function cpp3ds::RenderTarget::draw().
Definition at line 36 of file BlendMode.hpp.
Enumeration of the blending equations.
The equations are mapped directly to their OpenGL equivalents, specified by glBlendEquation() or glBlendEquationSeparate().
Enumerator | |
---|---|
Add |
Pixel = Src * SrcFactor + Dst * DstFactor. |
Subtract |
Pixel = Src * SrcFactor - Dst * DstFactor. |
Definition at line 64 of file BlendMode.hpp.
Enumeration of the blending factors.
The factors are mapped directly to their OpenGL equivalents, specified by glBlendFunc() or glBlendFuncSeparate().
Definition at line 44 of file BlendMode.hpp.
cpp3ds::BlendMode::BlendMode | ( | ) |
Default constructor.
Constructs a blending mode that does alpha blending.
cpp3ds::BlendMode::BlendMode | ( | Factor | sourceFactor, |
Factor | destinationFactor, | ||
Equation | blendEquation = Add |
||
) |
Construct the blend mode given the factors and equation.
This constructor uses the same factors and equation for both color and alpha components. It also defaults to the Add equation.
sourceFactor | Specifies how to compute the source factor for the color and alpha channels. |
destinationFactor | Specifies how to compute the destination factor for the color and alpha channels. |
blendEquation | Specifies how to combine the source and destination colors and alpha. |
cpp3ds::BlendMode::BlendMode | ( | Factor | colorSourceFactor, |
Factor | colorDestinationFactor, | ||
Equation | colorBlendEquation, | ||
Factor | alphaSourceFactor, | ||
Factor | alphaDestinationFactor, | ||
Equation | alphaBlendEquation | ||
) |
Construct the blend mode given the factors and equation.
colorSourceFactor | Specifies how to compute the source factor for the color channels. |
colorDestinationFactor | Specifies how to compute the destination factor for the color channels. |
colorBlendEquation | Specifies how to combine the source and destination colors. |
alphaSourceFactor | Specifies how to compute the source factor. |
alphaDestinationFactor | Specifies how to compute the destination factor. |
alphaBlendEquation | Specifies how to combine the source and destination alphas. |
Overload of the != operator.
left | Left operand |
right | Right operand |
Overload of the == operator.
left | Left operand |
right | Right operand |
Factor cpp3ds::BlendMode::alphaDstFactor |
Destination blending factor for the alpha channel.
Definition at line 113 of file BlendMode.hpp.
Equation cpp3ds::BlendMode::alphaEquation |
Blending equation for the alpha channel.
Definition at line 114 of file BlendMode.hpp.
Factor cpp3ds::BlendMode::alphaSrcFactor |
Source blending factor for the alpha channel.
Definition at line 112 of file BlendMode.hpp.
Factor cpp3ds::BlendMode::colorDstFactor |
Destination blending factor for the color channels.
Definition at line 110 of file BlendMode.hpp.
Equation cpp3ds::BlendMode::colorEquation |
Blending equation for the color channels.
Definition at line 111 of file BlendMode.hpp.
Factor cpp3ds::BlendMode::colorSrcFactor |
Source blending factor for the color channels.
Definition at line 109 of file BlendMode.hpp.