Texture

Image living on the graphics card that can be used for drawing.

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 Image, you need to prepare the pixels first and then upload them to the texture in a single operation (see Texture::update).

Texture makes it easy to convert from/to 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 Image, do whatever you need with the pixels, and then call Texture::loadFromImage.

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.

Like Image, Texture can handle a unique internal representation of pixels, which is RGBA 32 bits. This means that a pixel must be composed of 8 bits red, green, blue and alpha channels – just like a Color.

Constructors

this
this()
Undocumented in source.
this
this(sfTexture* texturePointer)
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

copyToImage
Image copyToImage()

Copy the texture pixels to an image.

create
bool create(uint width, uint height)

Create the texture.

getSize
Vector2u getSize()

Return the size of the texture.

isRepeated
bool isRepeated()

Tell whether the texture is repeated or not.

isSmooth
bool isSmooth()

Tell whether the smooth filter is enabled or not.

loadFromFile
bool loadFromFile(string filename, IntRect area)

Load the texture from a file on disk.

loadFromImage
bool loadFromImage(Image image, IntRect area)

Load the texture from an image.

loadFromMemory
bool loadFromMemory(const(void)[] data, IntRect area)

Load the texture from a file in memory.

loadFromStream
bool loadFromStream(InputStream stream, IntRect area)

Load the texture from a custom stream.

setRepeated
void setRepeated(bool repeated)

Enable or disable repeating.

setSmooth
void setSmooth(bool smooth)

Enable or disable the smooth filter.

updateFromImage
void updateFromImage(Image image, uint x, uint y)

Update the texture from an image.

updateFromPixels
void updateFromPixels(const(ubyte)[] pixels, uint width, uint height, uint x, uint y)

Update part of the texture from an array of pixels.

updateFromWindow
void updateFromWindow(Window window, uint x, uint y)

Update a part of the texture from the contents of a window.

updateFromWindow
void updateFromWindow(RenderWindow window, uint x, uint y)

Update a part of the texture from the contents of a window.

Properties

dup
Texture dup [@property getter]

Creates a new texture from the same data (this means copying the entire set of pixels).

Static functions

bind
void bind(Texture texture)

Bind a texture for rendering.

getMaximumSize
uint getMaximumSize()

Get the maximum texture size allowed.

Variables

sfPtr
sfTexture* sfPtr;
Undocumented in source.

See Also

Meta

Authors

Laurent Gomila, Jeremy DeHaan