Image canvases let you draw arbitrary graphics by writing directly to a palette-index pixel array and flushing it to the screen. Each canvas is backed by anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dRessedAlarm184/LWXGL/llms.txt
Use this file to discover all available pages before exploring further.
XImage and a matching byte array — you write palette indices (0–15) into the array, then call GUpdateImage to push only the changed pixels to the display.
LWXGL also provides a set of GPrimitive* drawing functions that operate on image canvases: GPrimitiveRect, GPrimitiveCircle, GPrimitiveLine, and GPrimitiveSprite. See their individual entries below.
GCreateImage
XImage of size w × h, a w*h-byte pixel array (initialized to 0), and a second copy of that array used to track which pixels have changed since the last GUpdateImage call.
Pixel at position (px, py) maps to array index py * w + px.
Element slot index. If the slot is already occupied the existing element (and its
XImage) is destroyed first.Left edge of the canvas in window pixels.
Top edge of the canvas in window pixels.
Canvas width in pixels.
Canvas height in pixels.
GGetImageData
w * h byte array of palette indices for canvas id. Write values 0–15 to this array to set pixel colors. The changes will not appear on screen until GUpdateImage is called.
Element slot index of an existing image element.
unsigned char* — pointer to the internal pixel data array. Do not free this pointer. It remains valid until the element is deleted or recreated.
GUpdateImage
XPutPixel only for those positions. After updating, the snapshot is synchronized with the current data.
This diff-based approach is efficient for canvases where only a small region changes per frame (e.g., a moving sprite on a static background). For canvases where every pixel changes, a full XPutImage would be faster — use GUpdateImage selectively in that case.
Element slot index of an existing image element.
GUpdateImage updates the XImage data structure but does not copy it to the window. The canvas is composited onto the back-buffer during the next GRenderWindow call via XPutImage.GClearImage
id with palette index c using memset. Call GUpdateImage afterwards to push the clear to the screen.
Element slot index of an existing image element.
Palette index (0–15) to fill with. Palette index
0 is typically black.GPrimitiveSprite
id. The sprite is positioned with its top-left corner at (sx, sy), drawn using the specified palette color, and scaled so that each logical pixel becomes a scale × scale block.
Pixels that would fall outside the canvas bounds are clipped silently.
Element slot index of the target image canvas.
X position (canvas-relative) of the sprite’s top-left corner.
Y position (canvas-relative) of the sprite’s top-left corner.
Palette index (0–15) used for filled (
#) pixels.Null-terminated RLE sprite string. See the format table below.
Pixel scale factor.
1 = 1:1, 2 = each logical pixel becomes a 2×2 block, etc.RLE sprite format
| Token | Meaning |
|---|---|
# | Draw one filled pixel (palette color), advance x by scale. |
. | Draw one background pixel (palette index 0), advance x by scale. |
$ | Newline — reset x to sx, advance y by scale. |
> | Skip — advance x by scale without drawing. |
N<token> | Repeat <token> N times. Example: 5# = 5 filled pixels. |
N[pattern] | Repeat pattern N times. Example: 3[#.] = #.#.#. |
! | End of sprite (optional — the null terminator also stops parsing). |
GPrimitiveSprite writes directly into the pixel array. Call GUpdateImage after all drawing is complete for a given frame to flush changes to the screen.