Struct sdl2::render::Texture [−][src]
pub struct Texture<'r> { /* fields omitted */ }
Expand description
A texture for a rendering context.
Every Texture is owned by a TextureCreator
. Internally, a texture is destroyed via its Drop
implementation. A texture can only be used by the Canvas
it was originally created from, it
is undefined behavior otherwise.
Implementations
Queries the attributes of the texture.
Sets an additional color value multiplied into render copy operations.
Gets the additional color value multiplied into render copy operations.
Sets an additional alpha value multiplied into render copy operations.
Gets the additional alpha value multiplied into render copy operations.
Sets the blend mode used for drawing operations (Fill and Line).
Gets the blend mode used for texture copy operations.
Updates the given texture rectangle with new pixel data.
pitch
is the number of bytes in a row of pixel data, including padding
between lines
- If
rect
isNone
, the entire texture is updated.
Updates a rectangle within a planar YV12 or IYUV texture with new pixel data.
Locks the texture for write-only pixel access. The texture must have been created with streaming access.
F
is a function that is passed the write-only texture buffer,
and the pitch of the texture (size of a row in bytes).
Remarks
As an optimization, the pixels made available for editing don’t necessarily contain the old texture data. This is a write-only operation, and if you need to keep a copy of the texture data you should do that at the application level.
Binds an OpenGL/ES/ES2 texture to the current context for use with when rendering OpenGL primitives directly.
Unbinds an OpenGL/ES/ES2 texture from the current context.
Binds and unbinds an OpenGL/ES/ES2 texture from the current context.
pub fn from_surface<'a, T>(
surface: &Surface<'_>,
texture_creator: &'a TextureCreator<T>
) -> Result<Texture<'a>, TextureValueError>
pub fn from_surface<'a, T>(
surface: &Surface<'_>,
texture_creator: &'a TextureCreator<T>
) -> Result<Texture<'a>, TextureValueError>
A convenience function for TextureCreator::create_texture_from_surface
.
use sdl2::pixels::PixelFormatEnum;
use sdl2::surface::Surface;
use sdl2::render::{Canvas, Texture};
use sdl2::video::Window;
// We init systems.
let sdl_context = sdl2::init().expect("failed to init SDL");
let video_subsystem = sdl_context.video().expect("failed to get video context");
// We create a window.
let window = video_subsystem.window("sdl2 demo", 800, 600)
.build()
.expect("failed to build window");
// We get the canvas from which we can get the `TextureCreator`.
let mut canvas: Canvas<Window> = window.into_canvas()
.build()
.expect("failed to build window's canvas");
let texture_creator = canvas.texture_creator();
let surface = Surface::new(512, 512, PixelFormatEnum::RGB24).unwrap();
let texture = Texture::from_surface(&surface, &texture_creator).unwrap();