RenderTexture


Object Hierarchy:

Object hierarchy for RenderTexture

Description:

[ Compact ]
[ CCode ( cname = "sfRenderTexture" , cprefix = "sfRenderTexture_" , free_function = "sfRenderTexture_destroy" ) ]
public class RenderTexture

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:

// Create a new render-window
var window = new RenderWindow(VideoMode(800, 600), "SFML window");

// Create a new render-texture
var texture = new RenderTexture (500, 500);

// The main loop
while (window.isOpen())
{
// Event processing
// ...

// Clear the whole texture with red color
texture.clear(sf.Color.Red);

// Draw stuff to the texture
texture.draw(sprite); // sprite is a sf.Sprite
texture.draw(shape); // shape is a sf.Shape
texture.draw(text); // text is a sf.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
var sprite = new Sprite () {texture = texture.getTexture};
window.draw(sprite);

// End the current frame and display its contents on screen
window.display();
}

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


Namespace: sf
Package: sfml

Content:

Creation methods:

Methods: