LWXGL’s image element acts as a palette-indexed pixel canvas backed by a per-element byte buffer. Each byte in the buffer is a palette index (0–15), and the renderer blits the corresponding color from the active 16-color palette to an X11 pixmap each frame. By writing to the buffer directly or through the primitive drawing functions and then callingDocumentation 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, you can achieve fully custom pixel-level rendering inside any element region.
Creating an Image Element
id— unique element IDx,y— top-left position in back-buffer coordinatesw,h— pixel dimensions of the canvas
w or h is zero or negative, the dimension expands relative to the remaining back-buffer space from the given origin using the formula bb.w - x + w (where w is the original argument). Concretely:
w = 0→ width fills to the right edge:bb.w - xw = -10→ width fills to the right edge minus 10px:bb.w - x - 10
CreateImage allocates two equal-sized buffers internally: data (writable) and prev (shadow copy for dirty-tracking). UpdateImage only re-pushes pixels that differ between the two, minimising X11 round-trips.Reading and Writing Pixels
GetImageData
(x, y) is at index y * width + x. Each byte is a palette index 0–15.
UpdateImage
data buffer to the X11 pixmap. Only changed pixels (compared to the internal prev shadow) are re-pushed. Call this once after a batch of pixel writes.
ClearImage
c using memset. This is the fastest way to reset the canvas.
Primitive Drawing Functions
All primitives write into the image element’sdata buffer. Call UpdateImage after drawing to commit changes to the screen.
PrimitiveRect — Rectangles
PrimitiveRect — Rectangles
fg and fills the interior with bg. Pass CLR_NONE (-1) for either to skip it.When fg == -1, fg is set equal to bg before drawing, producing a solid filled block with no distinct border.PrimitiveCircle — Circles
PrimitiveCircle — Circles
(cx, cy) with radius r. fg is the outline color and bg is the fill color. Either may be CLR_NONE.The fill test is dx² + dy² ≤ r²; the border test is |dx² + dy² − r²| < r.PrimitiveLine — Lines
PrimitiveLine — Lines
(x1, y1) and (x2, y2) using linear interpolation (DDA-style). Out-of-bounds pixels are clipped silently.PrimitiveTriangle — Triangles
PrimitiveTriangle — Triangles
PrimitiveLine. Pass CLR_NONE for fg or bg to skip the outline or fill respectively.PrimitiveSprite — RLE Sprites
PrimitiveSprite — RLE Sprites
(sx, sy) scaled by scale. The sprite uses a single foreground color for filled pixels.RLE sprite format
| Character | Meaning |
|---|---|
# | Filled pixel (drawn in color) |
. | Black pixel — writes palette index 0 (CLR_BLACK), not transparent |
$ | End of row — x resets to sx, y advances by scale |
> | Skip pixels — advances x by scale without writing any pixel |
0–9 | Digit prefix — repeat the next command N times (digits accumulate as a decimal number) |
[...] | Group — repeat the bracketed sub-expression (with optional digit prefix) |
! | Terminates the sprite string early |
RLE examples
The
. command writes palette index 0 (CLR_BLACK), not a transparent skip. To skip pixels without writing, use >.ApplyPixelFunc — Per-Pixel Transform
f. The callback receives the pixel’s x and y coordinates plus its current palette index, and returns the new palette index. The result is automatically clamped to 0–15 via % 16.
Custom Bitmap Font Rendering
Image elements support an optional 8×N bitmap font for drawing text directly into the pixel buffer.SetImageFont— installs a 256-glyph font where each glyph ishbytes tall and 8 bits wide. The buffer is copied internally (256 * hbytes).DrawString— renderstxtinto the image buffer starting at(x, y). Newlines (\n) advanceybyhand resetx. Glyphs are spaced 9px apart.
Immediate Drawing (No Element)
These functions draw directly onto the back-buffer each frame — useful for overlays and HUD elements that do not need to be retained as elements. Because they write to the back-buffer, they must be called from the frame callback (on_every).
ImmediateText adds 11 pixels to y internally before drawing. Passing y=0 renders the text baseline at y=11. Account for this offset when positioning text alongside other immediate draws.Example: Bouncing Ball Animation
This example creates a full-window canvas and animates a bouncing ball usingClearImage, PrimitiveCircle, and UpdateImage each frame.