LWXGL image canvases are pixel buffers indexed by the 16-color palette. You write palette indices into the buffer, callDocumentation 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.
GUpdateImage to flush changes to the XImage, and the canvas is composited into the window each frame. Because canvases use the same 16-color system as the rest of LWXGL, modifying the palette with GPaletteModify instantly affects all pixels on every canvas.
Creating an image canvas
w × h pixel canvas element positioned at (x, y). The pixel buffer is zero-initialized (palette index 0, typically black).
Accessing the pixel buffer
w * h byte array that backs the canvas. Each byte is a palette index in the range 0–15. The pixel at canvas coordinate (x, y) lives at offset y * width + x.
After modifying the buffer, you must call GUpdateImage to push the changes to the underlying XImage.
GUpdateImage
GClearImage
c using a single memset. This is faster than manually zeroing the buffer. Remember to call GUpdateImage afterwards.
Primitive drawing
LWXGL provides three functions that write directly into the canvas pixel buffer without requiring you to calculate pixel offsets yourself. Pixels outside the canvas bounds are silently clipped.Filled rectangle
fg is the border color and bg is the fill color (palette indices). Pass fg = -1 to draw a filled rectangle whose border is the same color as the fill (effectively borderless). Pass bg = -1 to draw an outline-only rectangle (the interior is not modified).
Filled circle
(cx, cy) with radius r. fg is the one-pixel-thick border color; bg is the fill color. Pass either as -1 to omit that part.
Line
(x1, y1) to (x2, y2) by stepping along the longer axis, rounding each coordinate to the nearest integer.
Example — drawing multiple primitives then flushing once:
Sprite rendering
(sx, sy). color is the foreground palette index. scale multiplies each logical pixel into a scale × scale block.
Sprite string format
| Character | Meaning |
|---|---|
# | Draw a pixel in color |
. | Draw a pixel in color 0 (black / background) |
$ | End of row — move to the next row, reset X to sx |
> | Skip one pixel position without drawing |
| Digit(s) before a character | Repeat the following character that many times: 5# = five filled pixels |
[...] with optional leading count | Repeat the group: 3[##.] = ##.##.##. |
Example — a 5×5 cross
Custom bitmap font
GDrawString can render text directly into the pixel buffer.
Font buffer layout: 256 consecutive entries (one per ASCII value), each h bytes tall. Each byte encodes one 8-pixel-wide row as a bitmask — bit 7 (MSB) is the leftmost pixel. Characters are rendered 9 pixels wide (8px glyph + 1px spacing). Newlines (\n, ASCII 10) move the cursor down by h pixels.
GImageSetFont on one canvas does not affect others.
Always call
GUpdateImage (or GRedrawAllImages) after any modification to the pixel buffer — whether through direct array writes, GClearImage, or the primitive functions. Changes are not visible on screen until a flush is performed.