Texture


Object Hierarchy:

Object hierarchy for Texture

Description:

[ Compact ]
[ Immutable ]
[ CCode ( cname = "sfTexture" , copy_function = "sfTexture_copy" , cprefix = "sfTexture_" , free_function = "sfTexture_destroy" ) ]
public class Texture

Texture stores pixels that can be drawn, with a sprite for example.

A texture lives in the graphics card memory, therefore it is very fast to draw a texture to a render target, or copy a render target to a texture (the graphics card can access both directly).

Being stored in the graphics card memory has some drawbacks. A texture cannot be manipulated as freely as a sf.Image, you need to prepare the pixels first and then upload them to the texture in a single operation (see Texture.update).

sf.Texture makes it easy to convert from/to sf.Image, but keep in mind that these calls require transfers between the graphics card and the central memory, therefore they are slow operations.

A texture can be loaded from an image, but also directly from a file/memory/stream. The necessary shortcuts are defined so that you don't need an image first for the most common cases. However, if you want to perform some modifications on the pixels before creating the final texture, you can load your file to a sf.Image, do whatever you need with the pixels, and then call Texture.fromImage.

Since they live in the graphics card memory, the pixels of a texture cannot be accessed without a slow copy first. And they cannot be accessed individually. Therefore, if you need to read the texture's pixels (like for pixel-perfect collisions), it is recommended to store the collision information separately, for example in an array of booleans sf.Texture stores pixels that can be drawn, with a sprite for example.

A texture lives in the graphics card memory, therefore it is very fast to draw a texture to a render target, or copy a render target to a texture (the graphics card can access both directly).

Being stored in the graphics card memory has some drawbacks. A texture cannot be manipulated as freely as a sf.Image, you need to prepare the pixels first and then upload them to the texture in a single operation (see Texture.update).

sf.Texture makes it easy to convert from/to sf.Image, but keep in mind that these calls require transfers between the graphics card and the central memory, therefore they are slow operations.

A texture can be loaded from an image, but also directly from a file/memory/stream. The necessary shortcuts are defined so that you don't need an image first for the most common cases. However, if you want to perform some modifications on the pixels before creating the final texture, you can load your file to a sf.Image, do whatever you need with the pixels, and then call Texture.fromImage.

Since they live in the graphics card memory, the pixels of a texture cannot be accessed without a slow copy first. And they cannot be accessed individually. Therefore, if you need to read the texture's pixels (like for pixel-perfect collisions), it is recommended to store the collision information separately, for example in an array of booleans

// This example shows the most common use of sf.Texture:
// drawing a sprite

// Load a texture from a file
Texture texture = new Texture.fromFile("texture.png");
if (texture == null)
return -1;

// Assign it to a sprite
var sprite = new Sprite ();
sprite.setTexture(texture);

// Draw the textured sprite
sprite.draw(window);
/


Namespace: sf
Package: sfml

Content:

Properties:

Static methods:

Creation methods:

Methods: