Type Definition ggez::graphics::Canvas [−][src]
type Canvas = CanvasGeneric<GlBackendSpec>;
A canvas that can be rendered to instead of the screen (sometimes referred
to as "render target" or "render to texture"). Set the canvas with the
ggez::graphics::set_canvas()
function, and then anything you
draw will be drawn to the canvas instead of the screen.
Resume drawing to the screen by calling ggez::graphics::set_canvas(None)
.
This is not an optimization tool. You may be tempted to say "I'll draw a scene
to a Canvas
and then just draw the single Canvas
each frame." This is technically
possible but makes life much harder than it needs to be (especially since the current
implementation of Canvas
has a number of hard-to-squash bugs.)
If you want to draw things maximally efficiently, use SpriteBatch
.
A Canvas
allows creating render targets to be used instead of
the screen. This allows graphics to be rendered to images off-screen
in order to do things like saving to an image file or creating cool effects
by using shaders that render to an image.
If you just want to draw multiple things efficiently, look at SpriteBatch
.
Methods
impl Canvas
[src]
impl Canvas
pub fn new(
ctx: &mut Context,
width: u32,
height: u32,
samples: NumSamples
) -> GameResult<Canvas>
[src]
pub fn new(
ctx: &mut Context,
width: u32,
height: u32,
samples: NumSamples
) -> GameResult<Canvas>
Create a new canvas with the given size and number of samples.
pub fn with_window_size(ctx: &mut Context) -> GameResult<Canvas>
[src]
pub fn with_window_size(ctx: &mut Context) -> GameResult<Canvas>
Create a new canvas with the current window dimensions.
pub fn get_image(&self) -> &Image
[src]
pub fn get_image(&self) -> &Image
Gets the backend Image
that is being rendered to.
pub fn into_inner(self) -> Image
[src]
pub fn into_inner(self) -> Image
Destroys the Canvas and returns the Image
it contains.
Trait Implementations
impl Drawable for Canvas
[src]
impl Drawable for Canvas
fn draw_ex(&self, ctx: &mut Context, param: DrawParam) -> GameResult<()>
[src]
fn draw_ex(&self, ctx: &mut Context, param: DrawParam) -> GameResult<()>
Actually draws the object to the screen. Read more
fn set_blend_mode(&mut self, mode: Option<BlendMode>)
[src]
fn set_blend_mode(&mut self, mode: Option<BlendMode>)
Sets the blend mode to be used when drawing this drawable. This overrides the general graphics::set_blend_mode()
. If None
is set, defers to the blend mode set by graphics::set_blend_mode()
. Read more
fn get_blend_mode(&self) -> Option<BlendMode>
[src]
fn get_blend_mode(&self) -> Option<BlendMode>
Gets the blend mode to be used when drawing this drawable.
fn draw(&self, ctx: &mut Context, dest: Point2, rotation: f32) -> GameResult<()>
[src]
fn draw(&self, ctx: &mut Context, dest: Point2, rotation: f32) -> GameResult<()>
Draws the drawable onto the rendering target. Read more