![]() |
Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
|
Target for off-screen 2D rendering into a texture. More...
#include <gf/RenderTexture.h>
Public Member Functions | |
RenderTexture (Vector2i size) | |
Create the render-texture. More... | |
void | setSmooth (bool smooth=true) |
Enable or disable texture smoothing. More... | |
bool | isSmooth () const |
Check if the smooth filtering is enabled or not. More... | |
void | setRepeated (bool repeated=true) |
Enable or disable texture repeating. More... | |
bool | isRepeated () const |
Check if the texture is repeated or not. More... | |
Vector2i | getSize () const override |
Return the size of the rendering region of the target. More... | |
void | resize (Vector2i size) |
Resize the underlying texture. More... | |
void | setActive () override |
Activate the render target for rendering. More... | |
void | display () |
Update the contents of the target texture. More... | |
Image | capture () const |
Copy the current contents of the render texture to an image. More... | |
const Texture & | getTexture () const |
Get a read-only reference to the target texture. More... | |
![]() | |
RenderTarget (Vector2i size) | |
Constructor. More... | |
virtual | ~RenderTarget () |
Destructor. More... | |
RenderTarget (const RenderTarget &)=delete | |
Deleted copy constructor. More... | |
RenderTarget & | operator= (const RenderTarget &)=delete |
Deleted copy assignment. More... | |
virtual Vector2i | getSize () const =0 |
Return the size of the rendering region of the target. More... | |
virtual void | setActive () |
Activate the render target for rendering. More... | |
Region | getCanonicalScissorBox () |
Get the current canonical scissor box. More... | |
void | setCanonicalScissorBox (const Region &box) |
Define the canonical scissor box. More... | |
RectI | getScissorBox () |
Get the current scissor box. More... | |
void | setScissorBox (const RectI &box) |
Define the scissor box. More... | |
void | clear (const Color4f &color) |
Clear the entire target with a single color. More... | |
void | clear () |
Clear the entire target. More... | |
RangeF | getAliasedLineWidthRange () const |
Get the range for aliased line width. More... | |
float | getLineWidth () const |
Get the line width. More... | |
void | draw (const Vertex *vertices, std::size_t count, PrimitiveType type, const RenderStates &states=RenderStates()) |
Draw primitives defined by an array of vertices. More... | |
void | draw (const Vertex *vertices, const uint16_t *indices, std::size_t count, PrimitiveType type, const RenderStates &states=RenderStates()) |
Draw primitives defined by an array of vertices and their indices. More... | |
void | draw (const VertexBuffer &buffer, const RenderStates &states=RenderStates()) |
Draw a vertex buffer to the render target. More... | |
void | draw (Drawable &drawable, const RenderStates &states=RenderStates()) |
Draw a drawable object to the render target. More... | |
void | customDraw (const void *vertices, std::size_t size, std::size_t count, PrimitiveType type, Span< const RenderAttributeInfo > attributes, const RenderStates &states=RenderStates()) |
Draw primitives defined by an array of custom vertices. More... | |
void | customDraw (const void *vertices, std::size_t size, const uint16_t *indices, std::size_t count, PrimitiveType type, Span< const RenderAttributeInfo > attributes, const RenderStates &states=RenderStates()) |
Draw primitives defined by an array of custom vertices and their indices. More... | |
void | customDraw (const VertexBuffer &buffer, Span< const RenderAttributeInfo > attributes, const RenderStates &states=RenderStates()) |
Draw a custom vertex buffer to the render target. More... | |
void | setView (const View &view) |
Change the current active view. More... | |
const View & | getView () const |
Get the view currently in use in the render target. More... | |
Region | getCanonicalViewport (const View &view) const |
Get the canonical viewport of a view, applied to this render target. More... | |
RectI | getViewport (const View &view) const |
Get the viewport of a view, applied to this render target. More... | |
Vector2f | mapPixelToCoords (Vector2i point, const View &view) const |
Convert a point from target coordinates to world coordinates. More... | |
Vector2f | mapPixelToCoords (Vector2i point) const |
Convert a point from target coordinates to world coordinates, using the current view. More... | |
Vector2i | mapCoordsToPixel (Vector2f point, const View &view) const |
Convert a point from world coordinates to target coordinates. More... | |
Vector2i | mapCoordsToPixel (Vector2f point) const |
Convert a point from world coordinates to target coordinates, using the current view. More... | |
Additional Inherited Members | |
![]() | |
Image | captureFramebuffer (unsigned name) const |
Capture the given framebuffer. More... | |
Target for off-screen 2D rendering into a texture.
gf::RenderTexture is the little brother of gf::RenderWindow. It implements the same 2D drawing and OpenGL-related functions (see their base class gf::RenderTarget for more details), the difference is that the result is stored in an off-screen texture rather than being show in a window.
Rendering to a texture can be useful in a variety of situations:
Usage example:
gf::RenderTexture::RenderTexture | ( | Vector2i | size | ) |
Create the render-texture.
size | Size of the render-texture |
Image gf::RenderTexture::capture | ( | ) | const |
Copy the current contents of the render texture to an image.
This is a slow operation, whose main purpose is to make screenshots of the application.
void gf::RenderTexture::display | ( | ) |
Update the contents of the target texture.
This function updates the target texture with what has been drawn so far. Like for windows, calling this function is mandatory at the end of rendering. Not calling it may leave the texture in an undefined state.
|
overridevirtual |
Return the size of the rendering region of the target.
Implements gf::RenderTarget.
|
inline |
Get a read-only reference to the target texture.
After drawing to the render-texture and calling display()
, you can retrieve the updated texture using this function, and draw it using a sprite (for example).
The internal sf::Texture of a render-texture is always the same instance, so that it is possible to call this function once and keep a reference to the texture even after it is modified.
|
inline |
|
inline |
Check if the smooth filtering is enabled or not.
void gf::RenderTexture::resize | ( | Vector2i | size | ) |
Resize the underlying texture.
size | The new size |
|
overridevirtual |
Activate the render target for rendering.
This function activates the render target. You should call this function before you want to draw something to the target.
Reimplemented from gf::RenderTarget.
|
inline |
Enable or disable texture repeating.
This function is similar to Texture::setRepeated()
. This parameter is disabled by default.
repeated | True to enable repeating, false to disable it |
|
inline |
Enable or disable texture smoothing.
This function is similar to Texture::setSmooth()
. This parameter is disabled by default.
smooth | True to enable smoothing, false to disable it |