LWXGL supports two external image formats: indexed-color TGA (Truevision TARGA, type 1 raw or type 9 RLE) and 1-bit XBM (X BitMap). Both are decoded into the same internal pixel store — an array of palette indices — and then drawn into image elements withDocumentation 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.
DrawIndexedTGA. A capture function lets you snapshot any rectangular region of the back-buffer as a TGA binary.
TGA Format Requirements
LWXGL only accepts TGA files that meet all of the following criteria:- Color-map type (
header[1]):1(color-mapped) - Image type (
header[2]):1(uncompressed) or9(RLE-compressed) - Color-map origin (
header[3-4]):0(must start at entry 0) - Color-map length (
header[5]):16(exactly 16 palette entries) - Color-map entry size (
header[6-7]):0, 24(24-bit BGR entries) - Bits per pixel (
header[16]):8 - Image descriptor (
header[17]):32(top-left origin) or0(bottom-left origin)
AllocateTGA
name. The decoded pixel data (palette indices) and 48-byte BGR palette are malloc’d and retained until DeleteTGA or program exit.
If a TGA with the same name already exists it is freed and replaced.
Return values:
| Value | Meaning |
|---|---|
0 | Success |
1 | File not found / could not open |
2 | Invalid TGA format (header check failed) |
Unique string key used to reference this image in subsequent calls.
Filesystem path to the
.tga file.If non-zero,
DrawIndexedTGA will replace the global 16-color palette with the palette embedded in this TGA file every time it is drawn.Palette index to treat as fully transparent (skipped when drawing). Pass
-1 to disable transparency.DrawIndexedTGA
id at offset (x, y) (image-local coordinates). Pixels equal to the transparent index are skipped. Pixels outside the image bounds are clipped.
If the TGA was loaded with change_palette = 1, the global palette is updated entry-by-entry before drawing, with a full RedrawAllImages triggered on the last entry.
Element slot index of the target image element.
X offset within the image where the TGA top-left corner is placed.
Y offset within the image where the TGA top-left corner is placed.
Key string used when the TGA was allocated. If not found, the call is a no-op.
CreateTGAImage
(0, 0), and calls UpdateImage. The internal allocation key is "TGAImage_" + path.
Element slot index to assign the new image element.
Window X position of the image element.
Window Y position of the image element.
Filesystem path to the
.tga file.Passed through to
AllocateTGA. See AllocateTGA for details.0 on success, or the AllocateTGA error code (1 or 2) on failure.
AllocateMemoryTGA
memfd_create file descriptor and passed to AllocateTGA via the /proc/self/fd/<n> path.
Return values are identical to AllocateTGA.
Unique string key to store the loaded image under.
Pointer to the raw TGA file bytes in memory.
Number of bytes in the buffer.
Due to the argument swap described above, this value is received by
AllocateTGA’s transparent parameter — it is treated as the palette index to skip when drawing (or -1 for no transparency).Due to the argument swap described above, this value is received by
AllocateTGA’s change_palette parameter — if non-zero, DrawIndexedTGA will replace the global palette with the TGA’s embedded palette every time it draws.AllocateMemoryTGA uses memfd_create, which is Linux-specific. It is not available on BSD or macOS.DeleteTGA
Key string of the TGA to remove.
AllocateXBM
DrawIndexedTGA). Each 1-bit pixel is mapped to one of two palette indices packed into the colors byte:
- High nibble of
colors(H(colors)) → palette index for bit-value1 - Low nibble of
colors(L(colors)) → palette index for bit-value0
transparent parameter controls which bit value is treated as transparent:
transparent | Transparent pixel |
|---|---|
1 | Bit-value 1 (high nibble index) |
0 | Bit-value 0 (low nibble index) |
| any other | No transparency |
1 on success, 0 on error (XBM file could not be read).
Unique string key for the loaded bitmap.
Filesystem path to the
.xbm file.Two palette indices packed into one byte. High nibble = color for
1 bits; low nibble = color for 0 bits. Example: 0xFC maps 1→CLR_WHITE(15), 0→CLR_CYAN(12).1 = 1-bits are transparent, 0 = 0-bits are transparent, any other = no transparency.CreateXBMImage
UpdateImage. The key is "XBMImage_" + path.
Returns 1 on success, 0 on failure.
Element slot index to assign the new image element.
Window X position of the image element.
Window Y position of the image element.
Filesystem path to the
.xbm file.Color mapping byte; same as
AllocateXBM.CaptureRegion
w × h pixel rectangle from the back-buffer starting at window coordinates (x, y) and encodes it as a valid indexed TGA binary in a freshly malloc’d buffer.
The returned buffer layout:
| Offset | Size | Content |
|---|---|---|
0 | 18 bytes | TGA header (type 1, 8bpp, top-left origin) |
18 | 48 bytes | 16-entry BGR palette (current LWXGL palette) |
66 | w * h bytes | Pixel data, row-major, each byte a palette index |
66 + w * h bytes.
The caller is responsible for calling free() on the returned pointer.
Left edge of the capture region, in window coordinates.
Top edge of the capture region, in window coordinates.
Width of the capture region in pixels.
Height of the capture region in pixels.