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 update).
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.
val window: RenderWindow = ???
val sprite: Sprite = ???
// This example shows the most common use of Texture: drawing a sprite
// Load a texture from a file
val texture = Texture()
if !(texture.loadFromFile("texture.png")) then
// error...
???
// Assign it to a sprite sf::Sprite sprite;
sprite.texture = texture
// Draw the textured sprite
window.draw(sprite)
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any