|
| RenderTexture () |
| Default constructor.
|
| RenderTexture (Vector2u size, const ContextSettings &settings={}) |
| Construct a render-texture.
|
| ~RenderTexture () override |
| Destructor.
|
| RenderTexture (const RenderTexture &)=delete |
| Deleted copy constructor.
|
RenderTexture & | operator= (const RenderTexture &)=delete |
| Deleted copy assignment.
|
| RenderTexture (RenderTexture &&) noexcept |
| Move constructor.
|
RenderTexture & | operator= (RenderTexture &&) noexcept |
| Move assignment operator.
|
bool | resize (Vector2u size, const ContextSettings &settings={}) |
| Resize the render-texture.
|
void | setSmooth (bool smooth) |
| Enable or disable texture smoothing.
|
bool | isSmooth () const |
| Tell whether the smooth filtering is enabled or not.
|
void | setRepeated (bool repeated) |
| Enable or disable texture repeating.
|
bool | isRepeated () const |
| Tell whether the texture is repeated or not.
|
bool | generateMipmap () |
| Generate a mipmap using the current texture data.
|
bool | setActive (bool active=true) override |
| Activate or deactivate the render-texture for rendering.
|
void | display () |
| Update the contents of the target texture.
|
Vector2u | getSize () const override |
| Return the size of the rendering region of the texture.
|
bool | isSrgb () const override |
| Tell if the render-texture will use sRGB encoding when drawing on it.
|
const Texture & | getTexture () const |
| Get a read-only reference to the target texture.
|
void | clear (Color color=Color::Black) |
| Clear the entire target with a single color.
|
void | clear (Color color, StencilValue stencilValue) |
| Clear the entire target with a single color and stencil value.
|
void | clearStencil (StencilValue stencilValue) |
| Clear the stencil buffer to a specific value.
|
void | setView (const View &view) |
| Change the current active view.
|
const View & | getView () const |
| Get the view currently in use in the render target.
|
const View & | getDefaultView () const |
| Get the default view of the render target.
|
IntRect | getViewport (const View &view) const |
| Get the viewport of a view, applied to this render target.
|
IntRect | getScissor (const View &view) const |
| Get the scissor rectangle of a view, applied to this render target.
|
Vector2f | mapPixelToCoords (Vector2i point) const |
| Convert a point from target coordinates to world coordinates, using the current view.
|
Vector2f | mapPixelToCoords (Vector2i point, const View &view) const |
| Convert a point from target coordinates to world coordinates.
|
Vector2i | mapCoordsToPixel (Vector2f point) const |
| Convert a point from world coordinates to target coordinates, using the current view.
|
Vector2i | mapCoordsToPixel (Vector2f point, const View &view) const |
| Convert a point from world coordinates to target coordinates.
|
void | draw (const Drawable &drawable, const RenderStates &states=RenderStates::Default) |
| Draw a drawable object to the render target.
|
void | draw (const Vertex *vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates &states=RenderStates::Default) |
| Draw primitives defined by an array of vertices.
|
void | draw (const VertexBuffer &vertexBuffer, const RenderStates &states=RenderStates::Default) |
| Draw primitives defined by a vertex buffer.
|
void | draw (const VertexBuffer &vertexBuffer, std::size_t firstVertex, std::size_t vertexCount, const RenderStates &states=RenderStates::Default) |
| Draw primitives defined by a vertex buffer.
|
void | pushGLStates () |
| Save the current OpenGL render states and matrices.
|
void | popGLStates () |
| Restore the previously saved OpenGL render states and matrices.
|
void | resetGLStates () |
| Reset the internal OpenGL states so that the target is ready for drawing.
|
Target for off-screen 2D rendering into a texture.
sf::RenderTexture is the little brother of sf::RenderWindow.
It implements the same 2D drawing and OpenGL-related functions (see their base class sf::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:
- precomputing a complex static texture (like a level's background from multiple tiles)
- applying post-effects to the whole scene with shaders
- creating a sprite from a 3D object rendered with OpenGL
- etc.
Usage example:
{
texture.draw(sprite);
texture.draw(shape);
texture.draw(text);
texture.display();
}
static const Color Red
Red predefined color.
void draw(const Drawable &drawable, const RenderStates &states=RenderStates::Default)
Draw a drawable object to the render target.
void clear(Color color=Color::Black)
Clear the entire target with a single color.
Target for off-screen 2D rendering into a texture.
Window that can serve as a target for 2D drawing.
Drawable representation of a texture, with its own transformations, color, etc.
VideoMode defines a video mode (size, bpp)
bool isOpen() const
Tell whether or not the window is open.
void display()
Display on screen what has been rendered to the window so far.
Like sf::RenderWindow, sf::RenderTexture is still able to render direct OpenGL stuff. It is even possible to mix together OpenGL calls and regular SFML drawing commands. If you need a depth buffer for 3D rendering, don't forget to request it when calling RenderTexture::create.
- See also
- sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
Definition at line 53 of file RenderTexture.hpp.
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.
- Parameters
-
point | Point to convert |
view | The view to use for converting the point |
- Returns
- The converted point, in target coordinates (pixels)
- See also
- mapPixelToCoords
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.
- Parameters
-
point | Pixel to convert |
view | The view to use for converting the point |
- Returns
- The converted point, in "world" units
- See also
- mapCoordsToPixel
void sf::RenderTarget::pushGLStates |
( |
| ) |
|
|
inherited |
Save the current OpenGL render states and matrices.
This function can be used when you mix SFML drawing and direct OpenGL rendering. Combined with popGLStates, it ensures that:
- SFML's internal states are not messed up by your OpenGL code
- your OpenGL states are not modified by a call to a SFML function
More specifically, it must be used around code that calls draw functions. Example:
window.pushGLStates();
window.draw(...);
window.draw(...);
window.popGLStates();
Note that this function is quite expensive: it saves all the possible OpenGL states and matrices, even the ones you don't care about. Therefore it should be used wisely. It is provided for convenience, but the best results will be achieved if you handle OpenGL states yourself (because you know which states have really changed, and need to be saved and restored). Take a look at the resetGLStates function if you do so.
- See also
- popGLStates