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.
sf::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 sf::Drawable object to a render target. It is part of the sf::RenderStates compound that is passed to the member function sf::RenderTarget::draw().
Definition at line 41 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 69 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 49 of file BlendMode.hpp.
sf::BlendMode::BlendMode | ( | ) |
Default constructor.
Constructs a blending mode that does alpha blending.
sf::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. |
sf::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 sf::BlendMode::alphaDstFactor |
Destination blending factor for the alpha channel.
Definition at line 118 of file BlendMode.hpp.
Equation sf::BlendMode::alphaEquation |
Blending equation for the alpha channel.
Definition at line 119 of file BlendMode.hpp.
Factor sf::BlendMode::alphaSrcFactor |
Source blending factor for the alpha channel.
Definition at line 117 of file BlendMode.hpp.
Factor sf::BlendMode::colorDstFactor |
Destination blending factor for the color channels.
Definition at line 115 of file BlendMode.hpp.
Equation sf::BlendMode::colorEquation |
Blending equation for the color channels.
Definition at line 116 of file BlendMode.hpp.
Factor sf::BlendMode::colorSrcFactor |
Source blending factor for the color channels.
Definition at line 114 of file BlendMode.hpp.