Target for off-screen 2D rendering into a texture.
// Create a new render-window auto window = new RenderWindow(VideoMode(800, 600), "DSFML window"); // Create a new render-texture auto texture = new RenderTexture(); if (!texture.create(500, 500)) return -1; // The main loop while (window.isOpen()) { // Event processing // ... // Clear the whole texture with red color texture.clear(Color.Red); // Draw stuff to the texture texture.draw(sprite); texture.draw(shape); texture.draw(text); // We're done drawing to the texture texture.display(); // Now we start rendering to the window, clear it first window.clear(); // Draw the texture auto sprite = new Sprite(texture.getTexture()); window.draw(sprite); // End the current frame and display its contents on screen window.display(); }
$(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`.)
$(RENDERTARGET_LINK), $(RENDERWINDOW_LINK), $(VIEW_LINK), $(TEXTURE_LINK)
$(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: