Public Types | Public Member Functions | Public Attributes | Related Functions | List of all members
cpp3ds::BlendMode Class Reference

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...
 

Detailed Description

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):

dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb
dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a

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:

cpp3ds::BlendMode alphaBlending = cpp3ds::BlendAlpha;
cpp3ds::BlendMode additiveBlending = cpp3ds::BlendAdd;
cpp3ds::BlendMode multiplicativeBlending = cpp3ds::BlendMultipy;
cpp3ds::BlendMode noBlending = cpp3ds::BlendNone;

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().

See also
cpp3ds::RenderStates, cpp3ds::RenderTarget

Definition at line 36 of file BlendMode.hpp.

Member Enumeration Documentation

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().

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

Constructor & Destructor Documentation

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.

Parameters
sourceFactorSpecifies how to compute the source factor for the color and alpha channels.
destinationFactorSpecifies how to compute the destination factor for the color and alpha channels.
blendEquationSpecifies 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.

Parameters
colorSourceFactorSpecifies how to compute the source factor for the color channels.
colorDestinationFactorSpecifies how to compute the destination factor for the color channels.
colorBlendEquationSpecifies how to combine the source and destination colors.
alphaSourceFactorSpecifies how to compute the source factor.
alphaDestinationFactorSpecifies how to compute the destination factor.
alphaBlendEquationSpecifies how to combine the source and destination alphas.

Friends And Related Function Documentation

bool operator!= ( const BlendMode left,
const BlendMode right 
)
related

Overload of the != operator.

Parameters
leftLeft operand
rightRight operand
Returns
True if blending modes are different, false if they are equal
bool operator== ( const BlendMode left,
const BlendMode right 
)
related

Overload of the == operator.

Parameters
leftLeft operand
rightRight operand
Returns
True if blending modes are equal, false if they are different

Member Data Documentation

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.


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