Image canvases are pixel-addressable bitmap elements. Each pixel stores a palette index (0–15); LWXGL maps those indices to actual RGB colors when flushing to the display. After writing pixels or drawing primitives, 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 the changes to screen. The update is diffed against the previous state — only modified pixels incur an XPutPixel call, keeping redraws efficient.
GCreateImage
XImage, a flat pixel data buffer of w * h bytes (one byte per pixel, holding a palette index), and a matching dirty-tracking “prev” buffer initialized to zero.
Element ID. If an element already exists at this ID it is deleted and replaced.
Left edge of the canvas in window pixels.
Top edge of the canvas in window pixels.
Canvas width in pixels.
Canvas height in pixels.
GGetImageData
w * h bytes. The pixel at canvas coordinate (x, y) is at index y * w + x and contains a palette index in the range 0–15.
Writes to this buffer are staged in memory. Call GUpdateImage to flush staged changes to the screen.
ID of an existing image canvas element.
unsigned char* — pointer to the element’s internal pixel buffer. Do not free this pointer.
Example
GUpdateImage
XPutPixel only for pixels that have changed. After processing, the prev buffer is synchronized with the current buffer. This makes repeated calls cheap when few pixels change between frames.
Call this function after any modification to the pixel buffer (via direct writes, GClearImage, or the drawing primitives in the Primitives API).
ID of an existing image canvas element.
GClearImage
c using memset. This is a fast bulk-fill — memset works correctly here because each pixel is exactly one byte.
This function does not call GUpdateImage. Call it explicitly afterwards to push the cleared canvas to the screen.
ID of an existing image canvas element.
Palette index (0–15) to fill every pixel with.
GRedrawAllImages
255 — and then calls GUpdateImage for each. Because 255 is not a valid palette index, every pixel is treated as changed, forcing a complete repaint.
Use this after GPaletteModify or GPaletteReset to re-render all images with updated palette colors. (Note: GPaletteModify accepts a redraw flag that does this automatically when set to 1.)
Example
GImageSetFont
GDrawString. The font buffer is copied internally, so the caller’s buffer may be freed after this call.
Font buffer format: 256 * h bytes total — 256 character slots × h bytes per character. Each byte encodes one horizontal row of the glyph as an 8-bit bitmask, MSB first (bit 7 = leftmost pixel).
If a font was previously attached to this element, its buffer is freed before the new one is copied.
ID of an existing image canvas element.
Pointer to a
256 * h byte bitmap font buffer.Glyph height in pixels (rows per character).
GDrawString
(x, y) using the bitmap font attached with GImageSetFont. Only set bits in each glyph row bitmap are painted — unset bits leave the canvas pixel unchanged, giving natural transparency.
- Character width: 9 px (8 px glyph + 1 px spacing).
- Newlines (ASCII code 10,
\n) advance the Y position by the font height and reset X to the originalxargument. - Pixels that fall outside the canvas bounds are silently clipped.
- Requires
GImageSetFontto have been called on the same element beforehand.
ID of an existing image canvas element with a font attached.
Left edge of the first character within the canvas.
Top edge of the first character within the canvas.
Null-terminated string to render.
Palette index (0–15) used for all set glyph pixels.