Struct sdl2::render::RenderTarget
[−]
[src]
pub struct RenderTarget<'renderer> { // some fields omitted }
A handle for getting/setting the render target of the render context.
Example
use sdl2::pixels::{Color, PixelFormatEnum}; use sdl2::rect::Rect; use sdl2::render::{Renderer, Texture}; // Draw a red rectangle to a new texture fn draw_to_texture(r: &mut Renderer) -> Texture { r.render_target() .expect("This platform doesn't support render targets") .create_and_set(PixelFormatEnum::RGBA8888, (512, 512)); // Start drawing r.clear(); r.set_draw_color(Color::RGB(255, 0, 0)); r.fill_rect(Rect::new_unwrap(100, 100, 256, 256)); let texture: Option<Texture> = r.render_target().unwrap().reset().unwrap(); texture.unwrap() }
Methods
impl<'renderer> RenderTarget<'renderer>
[src]
fn reset(&mut self) -> SdlResult<Option<Texture>>
Resets the render target to the default render target.
The old render target is returned if the function is successful.
fn set(&mut self, texture: Texture) -> SdlResult<Option<Texture>>
Sets the render target to the provided texture.
The texture must be created with the texture access: sdl2::render::TextureAccess::Target
.
The old render target is returned if the function is successful.
fn create_and_set(&mut self, format: PixelFormatEnum, (width, height): (u32, u32)) -> SdlResult<Option<Texture>>
Creates a new texture and sets it as the render target.
The old render target is returned if the function is successful.