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::{RenderDrawer, Texture};

// Draw a red rectangle to a new texture
fn draw_to_texture(drawer: &mut RenderDrawer) -> Texture {
    drawer.render_target()
        .expect("This platform doesn't support render targets")
        .create_and_set(PixelFormatEnum::RGBA8888, 512, 512);

    // Start drawing
    drawer.clear();
    drawer.set_draw_color(Color::RGB(255, 0, 0));
    drawer.fill_rect(Rect::new(100, 100, 256, 256));

    let texture: Option<Texture> = drawer.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: i32, height: i32) -> 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.