class Eagle::Canvas

Overview

An off-screen image you can draw into and then draw like a texture.

Canvases are useful for pixel-perfect low-resolution games (draw at 320x180, then scale up), for post-processing with a shader, for caching expensive drawings, and for minimaps.

canvas = Canvas.new(320, 180)
g.with_canvas(canvas) do
  g.clear(Color::BLACK)
  g.circle(160, 90, 40, color: Color::YELLOW)
end
g.draw(canvas, Window.rect) # scale up to fill the window

Pass depth: true if you render 3D into it.

Defined in:

eagle/graphics/canvas.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(width : Int32, height : Int32, depth : Bool = false, filter : GPU::Filter = Texture.default_filter) #

Creates a canvas of the given size.


Instance Method Detail

def depth? : Bool #

True when the canvas has a depth buffer for 3D rendering.


def dispose : Nil #

Frees the GPU resources.


def handle : GPU::RenderTargetHandle #

The GPU render-target handle.


def height : Int32 #

Height in pixels.


def rect : Rect #

The whole canvas as a Rect.


def size : Vec2 #

(width, height).


def texture : Texture #

The texture holding the canvas's pixels, for use with sprites or shaders.


def to_image : Image #

Reads the pixels back to the CPU. It is slow, so use it for screenshots and tests, not every frame.


def width : Int32 #

Width in pixels.