Gamedev Framework (gf)
0.3.0
A C++11 framework for 2D games
|
Blending modes for drawing. More...
#include <gf/Blend.h>
Public Member Functions | |
constexpr | BlendMode () |
Default constructor. More... | |
constexpr | BlendMode (BlendFactor sourceFactor, BlendFactor destinationFactor, BlendEquation equation=BlendEquation::Add) |
Construct the blend mode given the factors and equation. More... | |
constexpr | BlendMode (BlendFactor colorSourceFactor, BlendFactor colorDestinationFactor, BlendEquation colorBlendEquation, BlendFactor alphaSourceFactor, BlendFactor alphaDestinationFactor, BlendEquation alphaBlendEquation) |
Construct the blend mode given the factors and equation. More... | |
Public Attributes | |
BlendFactor | colorSrcFactor |
Source blending factor for the color channels. More... | |
BlendFactor | colorDstFactor |
Destination blending factor for the color channels. More... | |
BlendEquation | colorEquation |
Blending equation for the color channels. More... | |
BlendFactor | alphaSrcFactor |
Source blending factor for the alpha channel. More... | |
BlendFactor | alphaDstFactor |
Destination blending factor for the alpha channel. More... | |
BlendEquation | alphaEquation |
Blending equation for the alpha channel. More... | |
Related Functions | |
(Note that these are not member functions.) | |
constexpr bool | operator== (const BlendMode &lhs, const BlendMode &rhs) |
Equality operator. More... | |
Blending modes for drawing.
gf::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 gf::PredefinedBlendMonde
namespace:
A blend mode can be specified every time you draw a gf::Drawable object to a gf::RenderWindow. It is part of the gf::RenderStates compound that is passed to the member function gf::RenderTarget::draw().
|
inline |
Default constructor.
Constructs a blending mode that does alpha blending.
|
inline |
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. |
equation | Specifies how to combine the source and destination colors and alpha. |
|
inline |
Construct the blend mode given the factors and equation.
colorSourceFactor | Specifies how to compute the source function 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. |
Equality operator.
lhs | First blend mode |
rhs | Second blend mode |
BlendFactor gf::BlendMode::alphaDstFactor |
Destination blending factor for the alpha channel.
BlendEquation gf::BlendMode::alphaEquation |
Blending equation for the alpha channel.
BlendFactor gf::BlendMode::alphaSrcFactor |
Source blending factor for the alpha channel.
BlendFactor gf::BlendMode::colorDstFactor |
Destination blending factor for the color channels.
BlendEquation gf::BlendMode::colorEquation |
Blending equation for the color channels.
BlendFactor gf::BlendMode::colorSrcFactor |
Source blending factor for the color channels.