Blending modes for drawing. More...
#include <SFML/Graphics/BlendMode.hpp>
Public Types | |
enum class | Factor { Zero , One , SrcColor , OneMinusSrcColor , DstColor , OneMinusDstColor , SrcAlpha , OneMinusSrcAlpha , DstAlpha , OneMinusDstAlpha } |
Enumeration of the blending factors. More... | |
enum class | Equation { Add , Subtract , ReverseSubtract , Min , Max } |
Enumeration of the blending equations. More... | |
Public Member Functions | |
BlendMode ()=default | |
Default constructor. | |
BlendMode (Factor sourceFactor, Factor destinationFactor, Equation blendEquation=Equation::Add) | |
Construct the blend mode given the factors and equation. | |
BlendMode (Factor colorSourceFactor, Factor colorDestinationFactor, Equation colorBlendEquation, Factor alphaSourceFactor, Factor alphaDestinationFactor, Equation alphaBlendEquation) | |
Construct the blend mode given the factors and equation. | |
Public Attributes | |
Factor | colorSrcFactor {BlendMode::Factor::SrcAlpha} |
Source blending factor for the color channels. | |
Factor | colorDstFactor {BlendMode::Factor::OneMinusSrcAlpha} |
Destination blending factor for the color channels. | |
Equation | colorEquation {BlendMode::Equation::Add} |
Blending equation for the color channels. | |
Factor | alphaSrcFactor {BlendMode::Factor::One} |
Source blending factor for the alpha channel. | |
Factor | alphaDstFactor {BlendMode::Factor::OneMinusSrcAlpha} |
Destination blending factor for the alpha channel. | |
Equation | alphaEquation {BlendMode::Equation::Add} |
Blending equation for the alpha channel. | |
Related Symbols | |
(Note that these are not member symbols.) | |
bool | operator== (const BlendMode &left, const BlendMode &right) |
Overload of the operator== | |
bool | operator!= (const BlendMode &left, const BlendMode &right) |
Overload of the operator!= | |
Detailed Description
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:
- Color Source Factor (colorSrcFactor)
- Color Destination Factor (colorDstFactor)
- Color Blend Equation (colorEquation)
- Alpha Source Factor (alphaSrcFactor)
- Alpha Destination Factor (alphaDstFactor)
- Alpha Blend Equation (alphaEquation)
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()
.
- See also
sf::RenderStates
,sf::RenderTarget
Definition at line 40 of file BlendMode.hpp.
Member Enumeration Documentation
◆ Equation
|
strong |
Enumeration of the blending equations.
The equations are mapped directly to their OpenGL equivalents, specified by glBlendEquation() or glBlendEquationSeparate().
Definition at line 68 of file BlendMode.hpp.
◆ Factor
|
strong |
Enumeration of the blending factors.
The factors are mapped directly to their OpenGL equivalents, specified by glBlendFunc() or glBlendFuncSeparate().
Definition at line 48 of file BlendMode.hpp.
Constructor & Destructor Documentation
◆ BlendMode() [1/3]
|
default |
Default constructor.
Constructs a blending mode that does alpha blending.
◆ BlendMode() [2/3]
sf::BlendMode::BlendMode | ( | Factor | sourceFactor, |
Factor | destinationFactor, | ||
Equation | blendEquation = Equation::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.
- Parameters
-
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.
◆ BlendMode() [3/3]
sf::BlendMode::BlendMode | ( | Factor | colorSourceFactor, |
Factor | colorDestinationFactor, | ||
Equation | colorBlendEquation, | ||
Factor | alphaSourceFactor, | ||
Factor | alphaDestinationFactor, | ||
Equation | alphaBlendEquation ) |
Construct the blend mode given the factors and equation.
- Parameters
-
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.
Friends And Related Symbol Documentation
◆ operator!=()
Overload of the operator!=
- Parameters
-
left Left operand right Right operand
- Returns
true
if blending modes are different,false
if they are equal
◆ operator==()
Overload of the operator==
- Parameters
-
left Left operand right Right operand
- Returns
true
if blending modes are equal,false
if they are different
Member Data Documentation
◆ alphaDstFactor
Factor sf::BlendMode::alphaDstFactor {BlendMode::Factor::OneMinusSrcAlpha} |
Destination blending factor for the alpha channel.
Definition at line 123 of file BlendMode.hpp.
◆ alphaEquation
Equation sf::BlendMode::alphaEquation {BlendMode::Equation::Add} |
Blending equation for the alpha channel.
Definition at line 124 of file BlendMode.hpp.
◆ alphaSrcFactor
Factor sf::BlendMode::alphaSrcFactor {BlendMode::Factor::One} |
Source blending factor for the alpha channel.
Definition at line 122 of file BlendMode.hpp.
◆ colorDstFactor
Factor sf::BlendMode::colorDstFactor {BlendMode::Factor::OneMinusSrcAlpha} |
Destination blending factor for the color channels.
Definition at line 120 of file BlendMode.hpp.
◆ colorEquation
Equation sf::BlendMode::colorEquation {BlendMode::Equation::Add} |
Blending equation for the color channels.
Definition at line 121 of file BlendMode.hpp.
◆ colorSrcFactor
Factor sf::BlendMode::colorSrcFactor {BlendMode::Factor::SrcAlpha} |
Source blending factor for the color channels.
Definition at line 119 of file BlendMode.hpp.
The documentation for this class was generated from the following file: