LWXGL supports loading type-1 (palette-indexed) TGA images with an 8-bit color depth and a 16-entry BGR palette. These can be rendered onto image canvases, optionally replacing the global LWXGL palette so the image is displayed with its own colors.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 file format requirements
LWXGL validates the TGA header on load. The file must meet all of the following criteria:| Field | Required value |
|---|---|
| Image type (byte 2) | 1 — color-mapped (palette-indexed) |
| Color map type (byte 1) | 1 — color map present |
| Color map length (bytes 5–6, little-endian) | 16 entries |
| Color map entry size (byte 7) | 24 bits (BGR) |
| Pixel depth (byte 16) | 8 bits |
| Image descriptor (byte 17) | 0 (bottom-up) or 32 (top-down) |
| Width / Height (bytes 12–15) | Little-endian 16-bit each |
LWXGL validates the TGA header on load and returns an error code if the format doesn’t match. Use a graphics editor that supports indexed 8-bit TGA export with exactly 16 colors, such as GIMP (export as “raw color map TGA” with 256-color mode reduced to 16 entries).
Quick path — GCreateTGAImage
path, creates an image canvas element at (x, y) sized to match the image dimensions, draws the image into it, and flushes it to screen — all in one call.
change_palette = 1 replaces the LWXGL 16-color palette with the palette embedded in the TGA file.
Return values:
| Code | Meaning |
|---|---|
0 | Success |
1 | File could not be opened |
2 | Header validation failed (unsupported format) |
Two-step path — allocate then draw
GAllocateTGA reads the file into a named in-memory store. GDrawIndexedTGA then blits the pixels from that store into any image canvas at any position.
The name parameter is a user-chosen string key used to retrieve the allocation later.
GDrawIndexedTGA clips pixels that fall outside the canvas bounds, so you can safely draw a sprite partially off-screen.
GDeleteTGA frees the pixel and palette buffers associated with the name. Calling it with a name that was never allocated is a no-op.
Palette import
Whenchange_palette = 1 is set (either via GAllocateTGA or GCreateTGAImage), calling GDrawIndexedTGA iterates over all 16 palette entries from the TGA file and calls GPaletteModify for each one. The BGR values in the TGA palette are converted to RGB before being applied. After the last entry (index 15), GPaletteModify is called with redraw = 1, which triggers GRedrawAllImages to refresh every canvas so the new colors take effect immediately.