Image elements provide a pixel-level canvas you can write to with palette color indices, then flush to screen withDocumentation 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.
UpdateImage. Unlike other LWXGL elements that are declarative, image elements expose a raw byte buffer so you can implement any rendering logic — from simple fills to custom bitmap fonts — entirely in C.
Creating an Image Canvas
UseCreateImage to allocate an image element:
id parameter is an integer slot used to reference this element in all subsequent calls. x and y are the element’s position within the window.
Passing 0 or a negative value for w or h tells LWXGL to compute the dimension automatically so the image fills to the right (or bottom) edge of the back-buffer, offset by the given amount. For example, CreateImage(0, 10, 10, 0, -10) creates an image that fills the full remaining width and leaves a 10-pixel gap at the bottom.
The Image Data Buffer
GetImageData returns a pointer to the raw pixel buffer for an image element:
w × h bytes. Each byte is a palette index in the range 0–15 (mapping to LWXGL’s 16-color palette). Index 0 corresponds to CLR_BLACK, index 15 to CLR_WHITE, and so on.
To update the screen, write index values into the buffer and then call UpdateImage:
UpdateImage performs a dirty-pixel comparison against an internal shadow copy. Only pixels that have changed since the last call are transferred to the X11 pixmap, so calling it every frame even on a mostly-static image is inexpensive.
Clearing an Image
ClearImage fills the entire data buffer with a single palette index in one call:
memset-ing the buffer but uses the element’s actual dimensions automatically. Call UpdateImage afterward to push the cleared canvas to screen.
Primitive Drawing Functions
LWXGL provides several built-in drawing routines that write directly into an image element’s data buffer. None of them callUpdateImage — you must do that yourself after composing a frame.
PrimitiveRect
fg is the border (outline) color and bg is the fill color. If fg is CLR_NONE (-1), it is treated as equal to bg — the border is drawn in the fill color rather than skipped. Pass CLR_NONE for bg to skip filling interior pixels entirely, drawing only the border.
PrimitiveCircle
(cx, cy) with radius r. fg is the border color and bg is the fill color. Pass CLR_NONE (-1) for fg to skip drawing the border, or for bg to skip drawing the fill.
PrimitiveLine
(x1, y1) to (x2, y2) using incremental interpolation. Pixels outside the image bounds are clipped silently.
PrimitiveTriangle
fg is the edge color (drawn with PrimitiveLine along each side) and bg is the fill color. Pass CLR_NONE for either to omit it.
PrimitiveSprite
sx and sy are the top-left draw position. color is the palette index used for filled pixels — background pixels ('.') are always drawn as CLR_BLACK (index 0). scale is an integer pixel multiplier: 1 for 1:1, 2 for double-size, and so on.
Sprite RLE Format
Sprites passed toPrimitiveSprite use a compact run-length encoding string. The characters and their meanings are:
| Character | Meaning |
|---|---|
# | Draw a filled pixel in color |
. | Draw a background pixel (CLR_BLACK) |
$ | Move to the start of the next row |
> | Advance (skip) one pixel without drawing |
0–9 | Repeat count prefix for the next token |
[ … ] | Repeat the enclosed group (count prefix applies) |
2>— skip 2 pixels#— draw 1 filled pixel$— move to the next row (reset x tosx, advance y byscale)5#— draw 5 filled pixels on row 3$— move to the next row, and so on
The
'!' character acts as an early-terminator inside the RLE parser and will stop sprite rendering if it appears in the string. Do not use '!' in sprite data.Per-Pixel Transform
ApplyPixelFunc iterates every pixel in an image and replaces its color index with the value returned by a user-supplied function:
x and y coordinates plus its current palette index. The return value is taken modulo 16, so it is safe to return any integer. This is useful for palette cycling, brightness shifts, or procedural effects.
Custom Font Rendering
LWXGL supports per-image bitmap fonts for rendering text into image canvases. Setting the font:font_buffer must be a 256 × height-byte array where each character glyph occupies height bytes. Each byte encodes one row of 8 pixels, MSB first (bit 7 is the leftmost pixel). The buffer is copied internally, so it is safe to free or reuse after the call.
Rendering text:
text at pixel position (x, y) using the font set by SetImageFont. Characters are spaced 9 pixels apart. A newline character ('\n') advances the cursor down by height pixels and resets the x position to x. Call UpdateImage after drawing to push the result to screen.