LWXGL supports two bitmap formats for static image assets: TGA (8-bit indexed / palette-mapped Targa) and XBM (monochrome X11 bitmap). Both formats are decoded into an internal cache keyed by a caller-supplied name string, then blitted into anyDocumentation 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.
ImageElement canvas with DrawIndexedTGA. Convenience functions (CreateTGAImage, CreateXBMImage) wrap the full allocate → create → draw → update pipeline into a single call. A CaptureRegion function is also provided to snap a rectangular region of the back-buffer back into a TGA-formatted byte array for screenshots or compositing.
AllocateTGA
Loads an 8-bit indexed TGA file from disk into the internal TGA cache.
name, it is freed before the new one is stored.
Return values:
| Value | Meaning |
|---|---|
0 | Success. |
1 | File not found or could not be opened. |
2 | Invalid TGA format (wrong bit depth, type, or palette size). |
Unique cache key used to reference this TGA in subsequent calls. Must be a null-terminated string.
Filesystem path to the
.tga file.If non-zero, calling
DrawIndexedTGA with this TGA will replace the global 16-entry LWXGL palette with the colors embedded in the TGA file.Palette index (0–15) to treat as transparent when drawing. Pixels with this index are skipped. Pass
-1 for no transparency.AllocateMemoryTGA
Identical to AllocateTGA but reads TGA data from a memory buffer instead of a file path.
memfd file descriptor, writes buffer into it, then calls AllocateTGA via the /proc/self/fd/N path. The file descriptor is closed immediately after loading. Useful for embedding TGA assets in compiled code as byte arrays or for loading images received over a network.
Unique cache key for the loaded TGA.
Pointer to raw TGA file bytes in memory.
Number of bytes in
buffer.Non-zero to apply the TGA’s embedded palette to the global LWXGL palette on draw. Note: due to the parameter-swap bug described above, pass this value in the
transparent argument position to get the intended behavior.Palette index (0–15) to treat as transparent, or
-1 for none. Note: due to the parameter-swap bug, pass this value in the change_palette argument position to get the intended behavior.DeleteTGA
Frees the palette and pixel buffers associated with a named TGA cache entry.
name does not exist in the cache the call is a safe no-op. After deletion, any subsequent DrawIndexedTGA call using the same name will silently return without drawing anything.
Cache key of the TGA to free.
DrawIndexedTGA
Renders a previously allocated TGA into an image element’s pixel buffer at a given offset.
ImageElement data buffer. If change_palette was set when the TGA was allocated, the 16-entry global palette is updated from the TGA’s embedded BGR palette data before the pixels are drawn — each entry is applied sequentially and RedrawAllImages() is triggered on the final entry (index 15). Pixels whose index matches the transparent value are skipped. Pixels that fall outside the element bounds are clipped.
Call
UpdateImage(id) after DrawIndexedTGA to push the pixel buffer changes to the X11 pixmap and make them visible on screen.ID of the target
ImageElement.Horizontal offset within the image element where the TGA top-left should land.
Vertical offset within the image element where the TGA top-left should land.
Cache key of the previously allocated TGA to draw.
CreateTGAImage
Convenience function: loads a TGA from path, creates an image element sized to the TGA, draws it, and calls UpdateImage.
"TGAImage_" + path. If a TGA is already cached under that key (e.g., from a previous call with the same path), the allocation step is skipped. The transparent index is always set to -1 (no transparency). Returns 0 on success or the AllocateTGA error code on failure.
ID to assign to the newly created image element.
X position of the image element within the window.
Y position of the image element within the window.
Path to the
.tga file. Also used as part of the internal cache key.Non-zero to apply the TGA’s embedded palette to the global LWXGL palette.
AllocateXBM
Loads a monochrome XBM bitmap and stores it in the TGA cache as a two-color indexed image.
XReadBitmapFileData to parse the XBM. Each bit in the bitmap is mapped to one of two palette indices encoded in the colors parameter: the upper nibble becomes the foreground color (bit = 1) and the lower nibble the background color (bit = 0).
Return values:
| Value | Meaning |
|---|---|
1 | Success. |
0 | File not found or XBM parse error. |
Cache key for the loaded bitmap (shared with the TGA cache).
Filesystem path to the
.xbm file.Packed byte: upper nibble = foreground palette index (set bits), lower nibble = background palette index (clear bits). Example:
0xF0 = white foreground, black background.Controls which color is transparent when drawn.
1 = foreground index is transparent, 0 = background index is transparent, any other value = no transparency.CreateXBMImage
Convenience function: loads an XBM, creates an image element, draws it, and calls UpdateImage.
"XBMImage_" + path and skips re-allocation if the key is already cached. The transparent index is set to -1 (no transparency). Returns 1 on success or 0 on XBM load failure.
ID to assign to the newly created image element.
X position of the image element within the window.
Y position of the image element within the window.
Path to the
.xbm file.Packed foreground/background palette indices (upper/lower nibble).
CaptureRegion
Reads a rectangular region of the LWXGL back-buffer and returns it as a heap-allocated TGA file image.
w × h bytes of palette-indexed pixel data. The pixel data is stored top-to-bottom (origin flag byte 0x20 in the header). The buffer is heap-allocated with calloc — the caller is responsible for calling free() on it.
Left edge of the capture region in back-buffer coordinates.
Top edge of the capture region in back-buffer coordinates.
Width of the capture region in pixels.
Height of the capture region in pixels.
NULL on allocation failure.