An image element is a software-rendered canvas backed by a palette-indexed pixel buffer. Every pixel is stored as a single byte holding a palette index (0–15). Changes to the pixel buffer are not visible until you 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.
UpdateImage, which diffs the current buffer against the previous frame and only pushes changed pixels to the X server — keeping frame cost proportional to the area that actually changed.
CreateImage
(x, y) with dimensions w × h. Registers it in the element slot id.
If w or h is zero or negative, the dimension is expanded to fill the remaining back-buffer space relative to the given offset:
w = 0 gives a canvas that reaches the right edge of the window, and passing w = -20 leaves a 20-pixel margin on the right.
Internally, CreateImage allocates:
- An
XImage(ZPixmap, display depth) for the pixel data - A
databuffer (w * hbytes, palette indices, zero-initialised) - A
prevbuffer (w * hbytes) for diff-based dirty detection - An
imgdatabuffer (h * ximage->bytes_per_linebytes) that backs theXImagepixel storage - An off-screen
Pixmapof the same dimensions
Element slot index. Must be unique; an existing element at this index will be replaced.
Left edge of the image, in pixels, relative to the window origin.
Top edge of the image, in pixels, relative to the window origin.
Width in pixels. Pass
0 or a negative value to expand to the back-buffer width minus x (plus w as an offset).Height in pixels. Pass
0 or a negative value to expand to the back-buffer height minus y (plus h as an offset).GetImageData
id. The buffer is w * h bytes, stored in row-major order (left-to-right, top-to-bottom). Each byte is a palette index in the range 0–15.
Writing directly to this buffer and then calling UpdateImage is the primary way to draw into an image element.
Element slot index of the target image.
The returned pointer is valid until
DeleteElement(id) is called. Do not free() it — the buffer is owned by the element.UpdateImage
UpdateImage compares each byte in data against the corresponding byte in prev. For each changed pixel it calls put_pixel to write the new color into the XImage, then calls XPutImage once if any pixel changed. If nothing changed, no X calls are made.
Call this once per frame after all drawing operations are complete. Calling it multiple times per frame is safe but wasteful.
Element slot index of the target image.
ClearImage
c using memset. Equivalent to calling PrimitiveRect covering the whole image, but faster.
Element slot index of the target image.
Palette index (0–15) to fill with. Use the
CLR_* constants for readability.RedrawAllImages
prev buffer as invalid (fills with 255) then calls UpdateImage for each, ensuring all pixels are re-pushed to the X server regardless of whether data changed.
This is called automatically by PaletteModify when redraw = 1 and by PaletteReset. You rarely need to call it manually.
Because palette index
255 is not a valid 4-bit index, filling prev with 255 guarantees every pixel is treated as changed on the next UpdateImage pass.SetImageFont
h bytes tall and 8 pixels wide. Each byte is a row of 8 pixels, MSB first (bit 7 = leftmost pixel).
The buffer is copied internally, so it is safe to free() or reuse font after this call.
Element slot index of the target image.
Pointer to the font data. Must be exactly
256 * h bytes.Height of each glyph in pixels (i.e., the number of bytes per character).
DrawString
(x, y) using the custom font set by SetImageFont. Each character occupies a 9-pixel-wide cell (8 pixels of glyph + 1 pixel gap). Newline characters (\n, value 10) advance y by the font height and reset the horizontal cursor.
Pixels outside the image bounds are silently clipped.
Element slot index of the target image.
Left edge of the first character, in image-local coordinates.
Top edge of the first character row, in image-local coordinates.
Null-terminated string to draw. Supports
\n for line breaks.Palette index (0–15) for the drawn pixels. Background pixels are not affected — only the set bits in each glyph row are written.
ApplyPixelFunc
f modulo 16. The callback receives the pixel’s x and y coordinates within the image and its current palette index.
Use this for palette-rotation effects, noise, and per-pixel color transformations.
Element slot index of the target image.
Mapping function called for every pixel. The return value (mod 16) becomes the new palette index.