SFML 2.6.1

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Related Symbols | List of all members
sf::BlendMode Class Reference
Graphics module

Blending modes for drawing. More...

`#include <SFML/Graphics/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 , ReverseSubtract , Min , Max }
| Enumeration of the blending equations. More...

## Public Member Functions

| BlendMode ()
| Default constructor.
| BlendMode (Factor sourceFactor, Factor destinationFactor, Equation blendEquation=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
| Source blending factor for the color channels.
Factor | colorDstFactor
| Destination blending factor for the color channels.
Equation | colorEquation
| Blending equation for the color channels.
Factor | alphaSrcFactor
| Source blending factor for the alpha channel.
Factor | alphaDstFactor
| Destination blending factor for the alpha channel.
Equation | alphaEquation
| 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):

dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb
dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a
sf::BlendMode::colorSrcFactor
Factor colorSrcFactor
Source blending factor for the color channels.
Definition BlendMode.hpp:117
sf::BlendMode::alphaEquation
Equation alphaEquation
Blending equation for the alpha channel.
Definition BlendMode.hpp:122
sf::BlendMode::alphaSrcFactor
Factor alphaSrcFactor
Source blending factor for the alpha channel.
Definition BlendMode.hpp:120
sf::BlendMode::alphaDstFactor
Factor alphaDstFactor
Destination blending factor for the alpha channel.
Definition BlendMode.hpp:121
sf::BlendMode::colorDstFactor
Factor colorDstFactor
Destination blending factor for the color channels.
Definition BlendMode.hpp:118
sf::BlendMode::colorEquation
Equation colorEquation
Blending equation for the color channels.
Definition BlendMode.hpp:119

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:

sf::BlendMode alphaBlending = sf::BlendAlpha;
sf::BlendMode additiveBlending = sf::BlendAdd;
sf::BlendMode multiplicativeBlending = sf::BlendMultiply;
sf::BlendMode noBlending = sf::BlendNone;
sf::BlendMode
Blending modes for drawing.
Definition BlendMode.hpp:42

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 41 of file BlendMode.hpp.

## Member Enumeration Documentation

## ◆ Equation

enum sf::BlendMode::Equation

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.
ReverseSubtract | Pixel = Dst * DstFactor - Src * SrcFactor.
Min | Pixel = min(Dst, Src)
Max | Pixel = max(Dst, Src)

Definition at line 69 of file BlendMode.hpp.

## ◆ Factor

enum sf::BlendMode::Factor

Enumeration of the blending factors.

The factors are mapped directly to their OpenGL equivalents, specified by glBlendFunc() or glBlendFuncSeparate().

Enumerator
Zero | (0, 0, 0, 0)
One | (1, 1, 1, 1)
SrcColor | (src.r, src.g, src.b, src.a)
OneMinusSrcColor | (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
DstColor | (dst.r, dst.g, dst.b, dst.a)
OneMinusDstColor | (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
SrcAlpha | (src.a, src.a, src.a, src.a)
OneMinusSrcAlpha | (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
DstAlpha | (dst.a, dst.a, dst.a, dst.a)
OneMinusDstAlpha | (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)

Definition at line 49 of file BlendMode.hpp.

## Constructor & Destructor Documentation

## ◆ BlendMode() [1/3]

sf::BlendMode::BlendMode | ( |  | ) |

Default constructor.

Constructs a blending mode that does alpha blending.

## ◆ BlendMode() [2/3]

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.

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!=()

bool operator!= | ( | const BlendMode & | left,
|  | const BlendMode & | right
| ) |  |

related

Overload of the != operator.

Parameters

  left | Left operand
  right | Right operand

Returns
  True if blending modes are different, false if they are equal

## ◆ operator==()

bool operator== | ( | const BlendMode & | left,
|  | const BlendMode & | right
| ) |  |

related

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

Destination blending factor for the alpha channel.

Definition at line 121 of file BlendMode.hpp.

## ◆ alphaEquation

Equation sf::BlendMode::alphaEquation

Blending equation for the alpha channel.

Definition at line 122 of file BlendMode.hpp.

## ◆ alphaSrcFactor

Factor sf::BlendMode::alphaSrcFactor

Source blending factor for the alpha channel.

Definition at line 120 of file BlendMode.hpp.

## ◆ colorDstFactor

Factor sf::BlendMode::colorDstFactor

Destination blending factor for the color channels.

Definition at line 118 of file BlendMode.hpp.

## ◆ colorEquation

Equation sf::BlendMode::colorEquation

Blending equation for the color channels.

Definition at line 119 of file BlendMode.hpp.

## ◆ colorSrcFactor

Factor sf::BlendMode::colorSrcFactor

Source blending factor for the color channels.

Definition at line 117 of file BlendMode.hpp.

The documentation for this class was generated from the following file:

- BlendMode.hpp