Image elements are pixel-addressable XImage canvases embedded as regular LWXGL elements. Each pixel stores a palette index (0–15) rather than a raw color value, so the entire canvas recolors automatically when you modify the palette. After writing to the pixel 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 push changes to the X11 display.
Creating an Image
| Function | Description |
|---|---|
GCreateImage | Creates an image element of size w × h pixels at position (x, y). The pixel buffer is zero-initialized (all pixels set to palette index 0). |
GGetImageData | Returns a pointer to the w * h byte pixel buffer. Each byte holds a palette index 0–15. Data is stored row-major: pixel at (px, py) is at data[py * w + px]. |
GUpdateImage | Pushes dirty pixels from the buffer to the backing XImage, which is composited on the next GRenderWindow call. |
GClearImage | Fills the entire pixel buffer with palette index c using memset. Call GUpdateImage afterward to see the change. |
Drawing Primitives
All primitive functions operate on a specific image element byid and write palette indices directly into the pixel buffer. Call GUpdateImage(id) after any set of primitives to commit the changes.
Rectangles
fg is the border/outline color index; bg is the fill color index. Pass -1 for either to skip drawing that layer.
Circles
(cx, cy) with radius r. fg is drawn on border pixels (the annular ring one pixel wide at the edge); bg fills the interior. Pass -1 to skip either.
Lines
(x1, y1) to (x2, y2) using palette index color. The implementation uses a floating-point incremental algorithm equivalent to Bresenham’s — pixels are placed at each step by rounding the sub-pixel position.
Combined Example
Sprite Rendering
| Parameter | Description |
|---|---|
id | Target image element. |
sx, sy | Top-left origin of the sprite in image-local coordinates. |
color | Palette index used for filled (#) pixels. |
sprite | RLE-encoded sprite string (see format below). |
scale | Integer scale factor. Each logical pixel is rendered as a scale × scale block. |
Sprite String Format
The sprite string is a compact run-length encoding:| Token | Meaning |
|---|---|
# | Draw one filled pixel (using color). |
. | Draw one transparent pixel (palette index 0). |
$ | Newline — reset X to sx, advance Y by scale. |
N> | Skip N pixels horizontally (transparent). |
N# | Repeat # N times. |
N. | Repeat . N times. |
N[...] | Repeat the group [...] N times. |
The
$ newline token uses any preceding count as a row-repeat multiplier (y += count * scale), not as a pixel-column advance.Custom Bitmap Fonts
Image elements support loading a custom bitmap font for rendering text directly onto the canvas:Font Format
Thefont buffer must contain exactly 256 * h bytes — one entry per ASCII character (all 256 values), each h bytes tall. Each byte encodes one row of 8 pixels, MSB first (bit 7 = leftmost pixel). Characters are rendered 9 pixels wide (8 data pixels + 1 pixel gap between characters).
Rendering Text
GDrawString renders the string txt starting at (x, y) using the loaded font and palette index color. Newline (\n) advances the Y position by h pixels and resets X. Pixels outside the image bounds are clipped silently.
GImageSetFont copies the font data into a heap buffer owned by the image element. The original font pointer does not need to remain valid after the call. The buffer is freed when the element is deleted.Redrawing
GRedrawAllImages invalidates the shadow copy of every image element and calls GUpdateImage on each, forcing a full re-push of all pixel data to the X11 display. Call this after modifying the palette with GPaletteModify (with redraw=1) or GPaletteReset — both call it automatically. You can also call it manually if you need to force a full repaint.