LWXGL image canvases give you aDocumentation 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.
w × h array of palette indices — one unsigned char per pixel — that you manipulate directly, then flush to the screen with GUpdateImage. Canvases integrate with the normal widget system: they are rendered automatically every frame in ID order alongside buttons, text, and other elements.
Creating a Canvas
XImage at screen position (x, y) with dimensions w × h. The internal pixel buffer is zero-initialized (palette index 0 = black). The canvas is identified by id for all subsequent operations.
Direct Pixel Access
GGetImageData(id) returns a pointer to the raw w * h byte array. Pixels are stored in row-major order: pixel at (x, y) is at index y * width + x. Write any palette index 0–15 directly.
After modifying the buffer, call GUpdateImage(id) to push changes into the XImage. The update uses dirty-pixel detection — only pixels that differ from the previous frame are re-written, keeping updates fast even for large canvases.
Clearing a Canvas
c using memset. Fast for full-canvas resets before redrawing.
GRedrawAllImages() forces every image canvas to repaint fully by invalidating the dirty-pixel cache (sets the entire prev buffer to 255). This bypasses the dirty-pixel optimization so every pixel is re-written on the next GUpdateImage call. Call it after modifying the palette with GPaletteModify, since existing XImage pixels still show the old color until they are overwritten.Drawing Primitives
All primitive functions draw into the pixel buffer of the image canvas identified byid. They do not call GUpdateImage — you must do that yourself after drawing.
Filled Rectangle
fg is the border color index; bg is the fill color index. Pass -1 to skip either layer. Pixels outside the canvas bounds are silently clipped.
Filled Circle
(cx, cy) with radius r. fg is the 1-pixel-wide border color; bg is the interior fill. Pass -1 for either to skip it. Clipped to canvas bounds.
Line
(x1, y1) to (x2, y2) using linear interpolation (Bresenham-style). Each stepped pixel takes the given palette index. Clipped to canvas bounds.
Sprite
(sx, sy). Each logical pixel is rendered as a scale × scale block. The color argument sets the foreground (filled) pixel color; background pixels always use index 0.
RLE Sprite Format
Sprites are encoded as compact ASCII strings. The renderer parses them left-to-right, maintaining a current draw position that starts at(sx, sy).
| Token | Meaning |
|---|---|
# | Draw one foreground pixel (palette index color) and advance x by scale |
. | Draw one background pixel (palette index 0) and advance x by scale |
$ | Newline — reset x to sx and advance y by scale |
> | Skip one pixel horizontally (advance x by scale, no draw) |
N<token> | Repeat the following single token N times (e.g. 3# = three filled pixels) |
N[pattern] | Repeat the entire bracketed pattern N times (e.g. 3[#.] = #.#.#.) |
2[3[#].] repeats ###. twice.
Example — 5×5 cross: