Skip to content

canvas

canvas

Canvases are off-screen render targets you can draw into and then draw from.

You render to a canvas by calling nim2d.setCanvas(canvas) (see nim2d.nim), and you draw a canvas like an image with canvas.draw(...), which is shared with image.nim.

newCanvas

proc newCanvas(nim2d: Nim2d; width, height: int32): Canvas

An off-screen render target. Point drawing at it with setCanvas, then

draw it like any image.

Parameters

  • nim2d (Nim2d)
  • width (int32)
  • height (int32)

Returns

Canvas

newCanvas

proc newCanvas(nim2d: Nim2d): Canvas

A canvas the size of the window.

Parameters

  • nim2d (Nim2d)

Returns

Canvas

newImageData

proc newImageData(nim2d: Nim2d; canvas: Canvas): ImageData

Read a canvas's pixels back from the GPU into a new ImageData, which you

can inspect with getPixel or save to a PNG with encode. The renderer defers drawing until the end of the frame, so the pixels are what the canvas held after the last completed frame. Draw to the canvas in one frame and read it back in the next, in update, not in the middle of the draw that fills it.

Parameters

  • nim2d (Nim2d)
  • canvas (Canvas)

Returns

ImageData

Generated with mkdocstrings-nim