Loading...
Searching...
No Matches

Define the states used for drawing to a RenderTarget More...

#include <SFML/Graphics/RenderStates.hpp>

Public Member Functions

 RenderStates ()=default
 Default constructor.
 
 RenderStates (const BlendMode &theBlendMode)
 Construct a default set of render states with a custom blend mode.
 
 RenderStates (const StencilMode &theStencilMode)
 Construct a default set of render states with a custom stencil mode.
 
 RenderStates (const Transform &theTransform)
 Construct a default set of render states with a custom transform.
 
 RenderStates (const Texture *theTexture)
 Construct a default set of render states with a custom texture.
 
 RenderStates (const Shader *theShader)
 Construct a default set of render states with a custom shader.
 
 RenderStates (const BlendMode &theBlendMode, const StencilMode &theStencilMode, const Transform &theTransform, CoordinateType theCoordinateType, const Texture *theTexture, const Shader *theShader)
 Construct a set of render states with all its attributes.
 

Public Attributes

BlendMode blendMode {BlendAlpha}
 Blending mode.
 
StencilMode stencilMode
 Stencil mode.
 
Transform transform
 Transform.
 
CoordinateType coordinateType {CoordinateType::Pixels}
 Texture coordinate type.
 
const Texturetexture {}
 Texture.
 
const Shadershader {}
 Shader.
 

Static Public Attributes

static const RenderStates Default
 Special instance holding the default render states.
 

Detailed Description

Define the states used for drawing to a RenderTarget

There are six global states that can be applied to the drawn objects:

  • the blend mode: how pixels of the object are blended with the background
  • the stencil mode: how pixels of the object interact with the stencil buffer
  • the transform: how the object is positioned/rotated/scaled
  • the texture coordinate type: how texture coordinates are interpreted
  • the texture: what image is mapped to the object
  • the shader: what custom effect is applied to the object

High-level objects such as sprites or text force some of these states when they are drawn. For example, a sprite will set its own texture, so that you don't have to care about it when drawing the sprite.

The transform is a special case: sprites, texts and shapes (and it's a good idea to do it with your own drawable classes too) combine their transform with the one that is passed in the RenderStates structure. So that you can use a "global" transform on top of each object's transform.

Most objects, especially high-level drawables, can be drawn directly without defining render states explicitly – the default set of states is ok in most cases.

window.draw(sprite);

If you want to use a single specific render state, for example a shader, you can pass it directly to the Draw function: sf::RenderStates has an implicit one-argument constructor for each state.

window.draw(sprite, shader);
const Shader * shader
Shader.

When you're inside the Draw function of a drawable object (inherited from sf::Drawable), you can either pass the render states unmodified, or change some of them. For example, a transformable object will combine the current transform with its own transform. A sprite will set its texture. Etc.

See also
sf::RenderTarget, sf::Drawable

Definition at line 47 of file RenderStates.hpp.

Constructor & Destructor Documentation

◆ RenderStates() [1/7]

sf::RenderStates::RenderStates ( )
default

Default constructor.

Constructing a default set of render states is equivalent to using sf::RenderStates::Default. The default set defines:

  • the BlendAlpha blend mode
  • the default StencilMode (no stencil)
  • the identity transform
  • a nullptr texture
  • a nullptr shader

◆ RenderStates() [2/7]

sf::RenderStates::RenderStates ( const BlendMode & theBlendMode)

Construct a default set of render states with a custom blend mode.

Parameters
theBlendModeBlend mode to use

◆ RenderStates() [3/7]

sf::RenderStates::RenderStates ( const StencilMode & theStencilMode)

Construct a default set of render states with a custom stencil mode.

Parameters
theStencilModeStencil mode to use

◆ RenderStates() [4/7]

sf::RenderStates::RenderStates ( const Transform & theTransform)

Construct a default set of render states with a custom transform.

Parameters
theTransformTransform to use

◆ RenderStates() [5/7]

sf::RenderStates::RenderStates ( const Texture * theTexture)

Construct a default set of render states with a custom texture.

Parameters
theTextureTexture to use

◆ RenderStates() [6/7]

sf::RenderStates::RenderStates ( const Shader * theShader)

Construct a default set of render states with a custom shader.

Parameters
theShaderShader to use

◆ RenderStates() [7/7]

sf::RenderStates::RenderStates ( const BlendMode & theBlendMode,
const StencilMode & theStencilMode,
const Transform & theTransform,
CoordinateType theCoordinateType,
const Texture * theTexture,
const Shader * theShader )

Construct a set of render states with all its attributes.

Parameters
theBlendModeBlend mode to use
theStencilModeStencil mode to use
theTransformTransform to use
theCoordinateTypeTexture coordinate type to use
theTextureTexture to use
theShaderShader to use

Member Data Documentation

◆ blendMode

BlendMode sf::RenderStates::blendMode {BlendAlpha}

Blending mode.

Definition at line 131 of file RenderStates.hpp.

◆ coordinateType

CoordinateType sf::RenderStates::coordinateType {CoordinateType::Pixels}

Texture coordinate type.

Definition at line 134 of file RenderStates.hpp.

◆ Default

const RenderStates sf::RenderStates::Default
static

Special instance holding the default render states.

Definition at line 126 of file RenderStates.hpp.

◆ shader

const Shader* sf::RenderStates::shader {}

Shader.

Definition at line 136 of file RenderStates.hpp.

◆ stencilMode

StencilMode sf::RenderStates::stencilMode

Stencil mode.

Definition at line 132 of file RenderStates.hpp.

◆ texture

const Texture* sf::RenderStates::texture {}

Texture.

Definition at line 135 of file RenderStates.hpp.

◆ transform

Transform sf::RenderStates::transform

Transform.

Definition at line 133 of file RenderStates.hpp.


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