An sdl_canvas holds sdl_layer objects as an sdl_window does, but the SDL renderer draws them into a texture of the size of the canvas rather than on the screen. A layer shows the canvas as it shows an sdl_texture: placed in an area, scaled, rotated, blended or as the texture of an sdl_mesh. Canvases may show other canvases.
This is useful to:
.g., at a
smaller scale as a minimap.
<-clear @off,
drawing again keeps the old pixels and draws the layers on top.
The canvas is drawn again only after it changed: after a change to
one of its layers, to a texture or canvas these show, or after
sdl_canvas->render.
Each frame that shows the canvas keeps its own texture, drawn before the
frame itself. If the renderer loses its textures,
e.g., when the GPU is reset, the canvas is
drawn again; pixels kept using sdl_canvas<-clear @off
are then lost.
new(C, sdl_canvas(size(200, 200))), send(C, append, sdl_layer(ShipTexture, area(100, 100, 0, 0), none)), send(C, append, sdl_layer(FlameTexture, area(100, 140, 0, 0), none)), send(Window, append, new(L, sdl_layer(C, @nil, none))), send(L, transform, Transform). % moves ship and flame as one
The pixels of the canvas are in pixels of its own size. Layers placed with area @nil use the whole canvas. A canvas that shows itself, directly or through other canvases, is drawn without that layer and a warning is printed.
.g., for trails. Use sdl_canvas->render
to draw again, and a translucent layer in
sdl_canvas<-background
colour to make old pixels fade.
<-clear @off
to draw on top of the previous pixels without changing a layer.->render.