LWXGL image elements give you a pixel-addressable canvas that lives at an arbitrary position in the window. The canvas is backed by a flat byte array — one byte per pixel — where each byte holds a palette index (0–15). You manipulate this buffer directly or through the provided drawing primitives, then 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 screen. A dirty-tracking mechanism ensures only modified pixels are re-transferred on each update, keeping the operation efficient even for large canvases.
GCreateImage
w × h byte pixel buffer (data, zero-initialized), a matching w × h byte previous-frame buffer (prev, used for dirty tracking), and an XImage for X11 compositing. Any existing element at id is freed first.
Element slot index. If an element already exists at this ID it is freed and replaced.
X coordinate of the image’s top-left corner within the window.
Y coordinate of the image’s top-left corner within the window.
Width of the image canvas in pixels.
Height of the image canvas in pixels.
The pixel buffer is zero-initialized, so all pixels start at palette index 0. The XImage data buffer is also zero-initialized, meaning the image will appear as solid color 0 until you paint it and call
GUpdateImage.GGetImageData
w * h bytes, laid out in row-major order: pixel at column x, row y is at offset y * w + x. Write palette indices (0–15) into this buffer, then call GUpdateImage to push the changes to the screen.
Element slot index of the image to access.
unsigned char* pointing to the first byte of the w * h pixel buffer. This is not a copy — it is a direct pointer into the element’s internal storage. The pointer remains valid until the element is deleted with GDeleteElement.
GUpdateImage
XImage by scanning every pixel and comparing it against the previous-frame buffer (prev). Only pixels whose value differs from prev are re-encoded into the XImage, and prev is updated to match. This dirty-tracking keeps repeated partial updates efficient.
Element slot index of the image to update.
GUpdateImage only writes to the XImage in memory. The result becomes visible on screen during the next GRenderWindow call (or GSimpleWindowLoop frame), which blits the XImage onto the window’s back buffer.GClearImage
data) with the single palette index c using memset. Only the data buffer is cleared; the prev buffer is not touched, so a subsequent GUpdateImage will detect every pixel as dirty and re-transfer the full canvas.
Element slot index of the image to clear.
Palette index (0–15) to fill every pixel with.
GRedrawAllImages
prev buffer to 255 and immediately calling GUpdateImage. This bypasses the normal dirty-tracking optimization. It is called automatically by GPaletteModify (when redraw is non-zero) and GPaletteReset because existing XImage pixel data encodes old color values that are no longer valid after a palette change.
You rarely need to call
GRedrawAllImages directly. It is provided for cases where the X11 pixel cache may have become stale through external means.Drawing Primitives
The following functions draw directly into an image element’s pixel buffer. They do not callGUpdateImage — you must call GUpdateImage yourself after finishing all draw operations for a frame. All coordinates are relative to the image canvas’s own top-left corner (0, 0), not the window.
GPrimitiveRect
fg as the border color; all interior pixels use bg as the fill color. Pixels outside the image bounds are clipped silently.
Passing -1 for fg causes the border pixels to be drawn in bg instead (making the entire rectangle a solid fill). Passing -1 for bg skips the interior pixels entirely (hollow rectangle — only the border is drawn). If both are -1, nothing is drawn.
Element slot index of the target image.
X coordinate of the rectangle’s top-left corner, relative to the image canvas.
Y coordinate of the rectangle’s top-left corner, relative to the image canvas.
Width of the rectangle in pixels.
Height of the rectangle in pixels.
Palette index for the border. Pass
-1 to draw the border in bg color (solid rectangle).Palette index for the interior fill. Pass
-1 to skip the fill (hollow rectangle — border only).GPrimitiveCircle
(r-1)² and r² inclusive (one pixel wide). Interior pixels have squared distance less than (r-1)². Pass -1 for fg to skip the border, or -1 for bg to skip the fill. Pixels outside the image bounds are clipped.
Element slot index of the target image.
X coordinate of the circle’s center, relative to the image canvas.
Y coordinate of the circle’s center, relative to the image canvas.
Radius of the circle in pixels.
Palette index for the border ring. Pass
-1 to skip the border (filled circle only).Palette index for the interior fill. Pass
-1 to draw only the border ring.GPrimitiveLine
(x1, y1) to (x2, y2) using incremental floating-point stepping. The number of steps equals max(|dx|, |dy|), and each step advances by fractional amounts in both axes with coordinates rounded to the nearest pixel. Pixels outside the image bounds are skipped.
Element slot index of the target image.
X coordinate of the line’s start point, relative to the image canvas.
Y coordinate of the line’s start point, relative to the image canvas.
X coordinate of the line’s end point, relative to the image canvas.
Y coordinate of the line’s end point, relative to the image canvas.
Palette index (0–15) for the line color.
GPrimitiveSprite
(sx, sy) within the image canvas. Each foreground (#) pixel is painted with color; transparent (.) pixels write palette index 0. The scale parameter multiplies every logical pixel into a scale × scale block, enabling integer-scaled sprites without separate assets.
Element slot index of the target image.
X coordinate of the sprite’s top-left corner, relative to the image canvas.
Y coordinate of the sprite’s top-left corner, relative to the image canvas.
Palette index (0–15) used to paint foreground (
#) pixels.Null-terminated RLE sprite string. See the format reference below.
Pixel scale factor.
1 = 1:1, 2 = each logical pixel becomes a 2×2 block, etc.Sprite String Format
The sprite string is processed character-by-character from left to right. An optional numeric prefix accumulates a repeat count before a command character. Digits accumulate a decimal count; a non-digit command character consumes the count (defaulting to1 if no prefix was given).
| Token | Meaning |
|---|---|
# | Draw one foreground pixel (palette index = color parameter), advance X by scale. |
. | Draw one transparent pixel (palette index 0), advance X by scale. |
$ | Newline: reset X to sx, advance Y by scale. A preceding count N advances Y by N × scale. |
> | Skip right: advance X by scale without drawing. A preceding count N advances X by N × scale. |
N<cmd> | Repeat command <cmd> N times (e.g. 5# = five foreground pixels). |
N[...] | Repeat the group [...] N times (e.g. 3[#.] = #.#.#.). Groups may nest arbitrarily. |
! | End of sprite — processing stops immediately. |
The
> skip token does not draw any pixels — it only advances the X cursor. For example, 4> moves the cursor 4 logical pixels to the right (i.e., 4 × scale actual pixels) without writing anything.