dsfml.graphics.rendertexture

$(U RenderTexture) is the little brother of $(RENDERWINDOW_LINK). It implements the same 2D drawing and OpenGL-related functions (see their base class $(RENDERTARGET_LINK) 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.

Members

Classes

RenderTexture
class RenderTexture

Target for off-screen 2D rendering into a texture.

Examples

1 // Create a new render-window
2 auto window = new RenderWindow(VideoMode(800, 600), "DSFML window");
3 
4 // Create a new render-texture
5 auto texture = new RenderTexture();
6 if (!texture.create(500, 500))
7    return -1;
8 
9 // The main loop
10 while (window.isOpen())
11 {
12   // Event processing
13   // ...
14 
15   // Clear the whole texture with red color
16   texture.clear(Color.Red);
17 
18   // Draw stuff to the texture
19   texture.draw(sprite);
20   texture.draw(shape);
21   texture.draw(text);
22 
23   // We're done drawing to the texture
24   texture.display();
25 
26   // Now we start rendering to the window, clear it first
27   window.clear();
28 
29   // Draw the texture
30   auto sprite = new Sprite(texture.getTexture());
31   window.draw(sprite);
32 
33   // End the current frame and display its contents on screen
34   window.display();
35 }

$(PARA Like $(RENDERWINDOW_LINK), $(U RenderTexture) is still able to render direct OpenGL stuff. It is even possible to mix together OpenGL calls and regular DSFML drawing commands. If you need a depth buffer for 3D rendering, don't forget to request it when calling `RenderTexture.create`.)

See Also

$(RENDERTARGET_LINK), $(RENDERWINDOW_LINK), $(VIEW_LINK), $(TEXTURE_LINK)

Meta