LWXGL uses a fixed 16-entry indexed color palette rather than arbitrary RGB values. Every color in the library is expressed as a small integer index betweenDocumentation 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.
0 and 15, or the special sentinel CLR_NONE (-1) for transparency. The palette is allocated from the X colormap during CreateWindow and shared across all rendering operations, which means a single palette change instantly affects every widget and image that uses the modified index.
The 16 Palette Entries
The default palette is defined inmain.cc as the color_palette array. Named constants for each entry are declared in libLWXGL.h.
| Constant | Value | RGB |
|---|---|---|
CLR_NONE | -1 | Transparent / no-draw |
CLR_BLACK | 0x0 | 0, 0, 0 |
CLR_BLUE | 0x1 | 3, 3, 173 |
CLR_GREEN | 0x2 | 0, 170, 0 |
CLR_CYAN | 0x3 | 0, 168, 168 |
CLR_RED | 0x4 | 186, 6, 6 |
CLR_MAGENTA | 0x5 | 168, 0, 168 |
CLR_ORANGE | 0x6 | 230, 126, 34 |
CLR_LGRAY | 0x7 | 168, 168, 168 |
CLR_GRAY | 0x8 | 85, 87, 83 |
CLR_LBLUE | 0x9 | 87, 87, 255 |
CLR_LGREEN | 0xA | 85, 255, 85 |
CLR_LCYAN | 0xB | 96, 240, 240 |
CLR_LRED | 0xC | 255, 85, 85 |
CLR_LMAGENTA | 0xD | 240, 84, 240 |
CLR_YELLOW | 0xE | 244, 242, 54 |
CLR_WHITE | 0xF | 255, 255, 255 |
CLR_NONE is never stored in the palette array — it is a sentinel value recognized by drawing functions to mean “skip this draw.” The 16 real palette entries occupy indices 0x0 through 0xF.
Packing Two Colors into One int
Many element-creation functions accept a single int that encodes both a fill color and a border/outline color. The packing uses the low nibble for the fill and the high nibble for the border:
| Nibble | Meaning |
|---|---|
Low nibble (value & 0x0F) | Fill / interior color |
High nibble ((value >> 4) & 0x0F) | Border / outline color |
L(b) and H(b) macros defined in main.cc:
Building a Packed Color
Where Packed Colors Are Used
CreateButton accepts three packed-color arguments — one for each interactive state:
CreateInput, CreateCheckbox, and CreateConsole use the same packing scheme for their color parameters.
Runtime Palette Modification
The palette can be changed at any time afterCreateWindow using the three palette functions.
PaletteModify
idx with the new RGB values. Internally, XFreeColors releases the old pixel value and XAllocColor claims a new one. If redraw is non-zero, RedrawAllImages is called immediately to re-blit every ImageElement using the new color.
PaletteQuery
idx from the X colormap into the provided pointers. Useful for saving palette state before making temporary modifications.
PaletteReset
color_palette array in main.cc. Also calls RedrawAllImages to refresh pixel data.
Palette Changes and TGA Images
TGA images can be loaded with an option to replace the image’s black (RGB 0, 0, 0) pixels with the current palette color for a given index. Thechange_palette parameter in AllocateTGA, AllocateMemoryTGA, and CreateTGAImage enables this behavior:
PaletteModify is subsequently called with redraw = 1, RedrawAllImages re-applies this substitution using the updated color, so icons automatically recolor when the palette changes.