class
Eagle::Canvas
- Eagle::Canvas
- Reference
- Object
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.crConstructors
-
.new(width : Int32, height : Int32, depth : Bool = false, filter : GPU::Filter = Texture.default_filter)
Creates a canvas of the given size.
Instance Method Summary
-
#depth? : Bool
True when the canvas has a depth buffer for 3D rendering.
-
#dispose : Nil
Frees the GPU resources.
-
#handle : GPU::RenderTargetHandle
The GPU render-target handle.
-
#height : Int32
Height in pixels.
-
#rect : Rect
The whole canvas as a
Rect. -
#size : Vec2
(width, height). -
#texture : Texture
The texture holding the canvas's pixels, for use with sprites or shaders.
-
#to_image : Image
Reads the pixels back to the CPU.
-
#width : Int32
Width in pixels.
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
Reads the pixels back to the CPU. It is slow, so use it for screenshots and tests, not every frame.