BlendMode

sfml.graphics.BlendMode
See theBlendMode companion object
trait BlendMode(using ctor: ctor)

Blending modes for drawing.

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

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:

val alphaBlending = BlendMode.Alpha()
val additiveBlending = BlendMode.Add()
val multiplicativeBlending = BlendMode.Multiply()
val noBlending = BlendMode.None()

In SFML, a blend mode can be specified every time you draw a Drawable object to a render target. It is part of the RenderStates compound that is passed to the member function RenderTarget.draw().

Value parameters

alphaDstFactor

Destination blending factor for the alpha channel.

alphaEquation

Blending equation for the alpha channel.

alphaSrcFactor

Source blending factor for the alpha channel.

colorDstFactor

Destination blending factor for the color channels.

colorEquation

Blending equation for the color channels.

colorSrcFactor

Source blending factor for the color channels.

Attributes

See also
Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

Destination blending factor for the alpha channel.

Destination blending factor for the alpha channel.

Attributes

Blending equation for the alpha channel.

Blending equation for the alpha channel.

Attributes

Source blending factor for the alpha channel.

Source blending factor for the alpha channel.

Attributes

Destination blending factor for the color channels.

Destination blending factor for the color channels.

Attributes

Blending equation for the color channels.

Blending equation for the color channels.

Attributes

Source blending factor for the color channels.

Source blending factor for the color channels.

Attributes