Skip to content
Will Thomas edited this page Mar 31, 2014 · 2 revisions

Canvases are memory objects that act as render targets, compatible with a gpu component interface. They have all the same methods and behavior as the gpu itself, but everything happens in memory. When you're done with some complex drawing, you can then present to the gpu by calling the canvas' draw method.

A canvas is created like this:

local myCanvas=canvas.create(width,height,depth,parent)

All arguments are optional, and will default to the primary gpu and it's resolution and color depth if unspecified, so canvas.create() would create a full-screen canvas matching the current gpu settings.

You can draw to this canvas by calling it's methods, ex, myCanvas.fill(1,1,width,height,"x") would fill the entire canvas with "x" characters in the current foreground and background colors. All the gpu get and set methods can be called, with the same arguments, as documented on the OpenComputer wiki.

Note that while they have setResolution and setDepth methods, canvases do not currently support changing resolution or color depth, and any attempt to pass these functions anything but the current resolution and depth will throw an error, while passing the current values will return false, like the gpu equivalents.

Once you're done drawing and want the results to actually appear on screen, you just call the draw method.

myCanvas.draw(x,y)

This will make it draw to it's parent object, with it's top-left corner at position x,y.

see also: gfxBuffer Library

Clone this wiki locally