LWXGL supports two image formats natively: 8-bit color-mapped TGA (raw and RLE-compressed) and monochrome XBM bitmaps. Images are loaded into a named allocator cache and drawn into image canvas elements. Because LWXGL’s renderer is palette-indexed, both formats map cleanly onto the 16-color palette without any color-space conversion at draw time.Documentation 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.
TGA Requirements
TGA files must be 8-bit indexed (color-mapped). Both raw (image type 1) and RLE-compressed (image type 9) encoding are supported. The color map must contain exactly 16 entries at 24 bits per entry (BGR byte order, as written by most tools). Files that do not meet these criteria are rejected with an error code.Loading a TGA File
| Parameter | Description |
|---|---|
name | String key used to reference this TGA in all subsequent calls. |
path | Filesystem path to the .tga file. |
change_palette | If non-zero, the 16-entry color map embedded in the TGA is applied to the global LWXGL palette whenever the image is drawn with DrawIndexedTGA. |
transparent | Palette index to treat as transparent (skip when drawing). Pass -1 for no transparency. |
0— success1— file not found or could not be opened2— format invalid (not 8-bit indexed, wrong color-map size, etc.)
Loading a TGA from Memory
AllocateTGA but reads from an in-memory buffer rather than a file path. LWXGL uses memfd_create internally to present the buffer as a file descriptor, then calls the standard TGA loader on it. This is useful for TGA data compiled into the binary or received over a network. Return values are the same as AllocateTGA.
Drawing a TGA into an Image Element
After loading a TGA, render it into an image canvas element:id must be an existing image element (created with CreateImage). The TGA is rendered at offset (x, y) within the image’s pixel buffer. If change_palette was set when the TGA was allocated, DrawIndexedTGA applies the TGA’s color map to the global LWXGL palette before drawing. Call UpdateImage(id) afterward to push the result to screen.
Convenience Function
CreateTGAImage combines AllocateTGA + CreateImage + DrawIndexedTGA + UpdateImage in a single call:
-1 (no transparent index). Returns 0 on success, or a non-zero AllocateTGA error code if the file could not be loaded.
Freeing a TGA
DrawIndexedTGA with the same name silently do nothing.
XBM Images
LWXGL can load monochrome XBM bitmaps and store them in the same TGA allocator cache:name— allocator cache key.path— filesystem path to the.xbmfile (parsed withXReadBitmapFileData).colors— a packed nibble pair0xFBwhere the upper nibble is the foreground palette index and the lower nibble is the background palette index. For example,0xF0maps1-bits toCLR_WHITEand0-bits toCLR_BLACK.transparent:0= background pixels are transparent,1= foreground pixels are transparent, any other value = no transparency.
1 on success, 0 if XReadBitmapFileData fails (file not found or parse error).
XBM Convenience Function
"XBMImage_" + path. Returns 1 on success, 0 on failure.
Capturing Screen Regions
CaptureRegion reads a rectangular region of pixels from the LWXGL back-buffer and returns it as an in-memory TGA file:
malloc and must be freed by the caller with free(). This is useful for saving screenshots, caching rendered frames, or feeding back into AllocateMemoryTGA.
The TGA capture buffer size is always
66 + w * h bytes: 18-byte header + 48-byte color map (16 × 3 bytes) + w × h pixel indices.