Base class for all render targets (window, texture, ...)
RenderTarget defines the common behavior of all the 2D render targets usable in the graphics module.
It makes it possible to draw 2D entities like sprites, shapes, text without using any OpenGL command directly.
A RenderTarget is also able to use views (View), which are a kind of 2D cameras. With views you can globally scroll, rotate or zoom everything that is drawn, without having to transform every single entity. See the documentation of View for more details and sample pieces of code about this class.
On top of that, render targets are still able to render direct OpenGL stuff. It is even possible to mix together OpenGL calls and regular SFML drawing commands. When doing so, make sure that OpenGL states are not messed up by calling the pushGLStates/popGLStates functions.
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
trait RenderTexturetrait RenderWindow
Members list
Value members
Concrete methods
Activate or deactivate the render target for rendering.
Activate or deactivate the render target for rendering.
This function makes the render target's context current for future OpenGL rendering operations (so you shouldn't care about it if you're not doing direct OpenGL stuff). A render target's context is active only on the current thread, if you want to make it active on another thread you have to deactivate it on the previous thread first if it was active. Only one context can be current in a thread, so if you want to draw OpenGL geometry to another render target don't forget to activate it again. Activating a render target will automatically deactivate the previously active context (if any).
Value parameters
- active
-
true to activate, false to deactivate
Attributes
- Returns
-
true if operation was successful, false otherwise
Clear the entire target with a single color.
Clear the entire target with a single color.
This function is usually called once every frame, to clear the previous contents of the target.
Value parameters
- color
-
Fill color to use to clear the render target
Attributes
Clear the stencil buffer to a specific value.
Clear the stencil buffer to a specific value.
The specified value is truncated to the bit width of the current stencil buffer.
Value parameters
- stencilValue
-
Stencil value to clear to
Attributes
Clear the entire target with a single color and stencil value.
Clear the entire target with a single color and stencil value.
The specified stencil value is truncated to the bit width of the current stencil buffer.
Value parameters
- color
-
Fill color to use to clear the render target
- stencilValue
-
Stencil value to clear to
Attributes
Draw a drawable object to the render target.
Draw a drawable object to the render target.
Value parameters
- drawable
-
Object to draw states Render states to use for drawing
Attributes
Tell if the render target will use sRGB encoding when drawing on it.
Tell if the render target will use sRGB encoding when drawing on it.
Attributes
- Returns
-
true if the render target use sRGB encoding, false otherwise
Convert a point from world coordinates to target coordinates, using the current view.
Convert a point from world coordinates to target coordinates, using the current view.
This function is an overload of the mapCoordsToPixel function that implicitly uses the current view. It is equivalent to:
import sfml.system.Vector2
val target: RenderTarget = ???
val point: Vector2[Int] = ???
target.mapCoordsToPixel(point, target.view)
Value parameters
- point
-
Point to convert
Attributes
- Returns
-
The converted point, in target coordinates (pixels)
- See also
Convert a point from world coordinates to target coordinates.
Convert a point from world coordinates to target coordinates.
This function finds the pixel of the render target that matches the given 2D point. In other words, it goes through the same process as the graphics card, to compute the final position of a rendered point.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render target, this assertion is not true anymore, i.e. a point located at (150, 75) in your 2D world may map to the pixel (10, 50) of your render target – if the view is translated by (140, 25).
This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render target.
Value parameters
- point
-
Point to convert
- view
-
The view to use for converting the point
Attributes
- Returns
-
The converted point, in target coordinates (pixels)
- See also
Convert a point from target coordinates to world coordinates, using the current view.
Convert a point from target coordinates to world coordinates, using the current view.
This function is an overload of the mapPixelToCoords function that implicitly uses the current view. It is equivalent to:
import sfml.system.Vector2
val target: RenderTarget = ???
val point: Vector2[Int] = ???
target.mapPixelToCoords(point, target.view)
Value parameters
- point
-
Pixel to convert
Attributes
- Returns
-
The converted point, in "world" coordinates
- See also
Convert a point from target coordinates to world coordinates.
Convert a point from target coordinates to world coordinates.
This function finds the 2D position that matches the given pixel of the render target. In other words, it does the inverse of what the graphics card does, to find the initial position of a rendered pixel.
Initially, both coordinate systems (world units and target pixels) match perfectly. But if you define a custom view or resize your render target, this assertion is not true anymore, i.e. a point located at (10, 50) in your render target may map to the point (150, 75) in your 2D world – if the view is translated by (140, 25).
For render-windows, this function is typically used to find which point (or object) is located below the mouse cursor.
This version uses a custom view for calculations, see the other overload of the function if you want to use the current view of the render target.
Value parameters
- point
-
Pixel to convert
- view
-
The view to use for converting the point
Attributes
- Returns
-
The converted point, in "world" units
- See also
Get the scissor rectangle of a view, applied to this render target.
Get the scissor rectangle of a view, applied to this render target.
The scissor rectangle is defined in the view as a ratio. This function simply applies this ratio to the current dimensions of the render target to calculate the pixels rectangle that the scissor rectangle actually covers in the target.
Value parameters
- view
-
The view for which we want to compute the scissor rectangle
Attributes
- Returns
-
Scissor rectangle, expressed in pixels
Get the view currently in use in the render target.
Get the view currently in use in the render target.
Attributes
- Returns
-
The view object that is currently used
- See also
Change the current active view.
Change the current active view.
The view is like a 2D camera, it controls which part of the 2D scene is visible, and how it is viewed in the render target. The new view will affect everything that is drawn, until another view is set. The render target keeps its own copy of the view object, so it is not necessary to keep the original one alive after calling this function. To restore the original view of the target, you can pass the result of defaultView to this function.
Value parameters
- view
-
New view to use
Attributes
- See also
Get the viewport of a view, applied to this render target.
Get the viewport of a view, applied to this render target.
The viewport is defined in the view as a ratio, this function simply applies this ratio to the current dimensions of the render target to calculate the pixels rectangle that the viewport actually covers in the target.
Value parameters
- view
-
The view for which we want to compute the viewport
Attributes
- Returns
-
Viewport rectangle, expressed in pixels