Skip to main content

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.

LWXGL uses a fixed 16-entry indexed palette, where every color in the system is identified by an integer index from 0 to 15. Every color parameter throughout the API — background colors, foreground colors, button states, text colors, and image pixel data — takes a palette index rather than a direct RGB value. This keeps the API uniform and makes it straightforward to retheme an entire application by changing a handful of palette entries. The special constant CLR_NONE (-1) means “no color” or transparent, and is accepted wherever a fill or background color is optional.

Default Palette

The 16 default colors are defined in main.cc and allocated into the X11 colormap when CreateWindow is called. Named constants for each index are declared in libLWXGL.h.
IndexConstantDefault ColorRGB
0CLR_BLACKBlack0, 0, 0
1CLR_BLUEDark Blue3, 3, 173
2CLR_GREENDark Green0, 170, 0
3CLR_CYANDark Cyan0, 168, 168
4CLR_REDDark Red186, 6, 6
5CLR_MAGENTADark Magenta168, 0, 168
6CLR_ORANGEOrange230, 126, 34
7CLR_LGRAYLight Gray168, 168, 168
8CLR_GRAYDark Gray85, 87, 83
9CLR_LBLUELight Blue87, 87, 255
10CLR_LGREENLight Green85, 255, 85
11CLR_LCYANLight Cyan96, 240, 240
12CLR_LREDLight Red255, 85, 85
13CLR_LMAGENTALight Magenta240, 84, 240
14CLR_YELLOWYellow244, 242, 54
15CLR_WHITEWhite255, 255, 255
All 16 colors are allocated into the default X11 colormap during CreateWindow. If any allocation fails, CreateWindow returns 127 + i where i is the index of the first failing entry.

Using Color Constants

Pass the named constants anywhere the API accepts a color parameter. This applies to CreateWindow, CreateText, CreateButton, CreateRect, CreateEllipse, CreateConsole, and all immediate-mode drawing functions:
// White text on a black window background
CreateWindow(800, 600, "Demo", CLR_BLACK);

// A label in light cyan
CreateText(0, 20, 20, "Score: 0", CLR_LCYAN);

// A button with three color states: normal, hover, pressed
CreateButton(1, 20, 50, 100, 30, CLR_BLUE, CLR_LBLUE, CLR_CYAN, "Start", on_start);

// A filled rectangle with an orange border and dark background
CreateRect(2, 0, 0, 800, 40, CLR_ORANGE, CLR_GRAY);

// Pass CLR_NONE to suppress the background fill entirely
CreateRect(3, 10, 10, 200, 200, CLR_WHITE, CLR_NONE);

Querying Palette Entries

PaletteQuery reads the current RGB values for a given palette slot. The values are written into the three unsigned char pointers you provide:
unsigned char r, g, b;
PaletteQuery(CLR_ORANGE, &r, &g, &b);
// r=230, g=126, b=34 by default
The values returned reflect the current state of the X11 colormap — they will differ from the defaults if the palette has been modified with PaletteModify.

Modifying Palette Entries

PaletteModify replaces one palette slot with a new RGB color and optionally redraws all image elements so they reflect the change:
// Replace CLR_BLUE with a custom navy color, then redraw images
PaletteModify(CLR_BLUE, 0, 0, 128, 1);

// Change a color without triggering a redraw (faster, deferred)
PaletteModify(CLR_GRAY, 60, 60, 60, 0);
Setting redraw to a non-zero value calls RedrawAllImages internally, which regenerates the pixel data for every Image element (type 4) using the updated palette. If you are modifying several entries at once, pass 0 for all but the last call to avoid redundant redraws:
PaletteModify(CLR_RED,     200, 0,   0,  0); // no redraw yet
PaletteModify(CLR_LRED,    255, 80,  80, 0); // no redraw yet
PaletteModify(CLR_MAGENTA, 180, 0,  180, 1); // redraw once at the end
Modifying a palette entry affects every element that uses that color index — including Image elements whose pixel data stores color indices rather than RGB values. A single PaletteModify call can visually alter buttons, text, rectangles, and all loaded images simultaneously.

Resetting the Palette

PaletteReset restores all 16 entries to the built-in defaults shown in the table above and always triggers a full image redraw:
PaletteReset();
This is equivalent to calling PaletteModify sixteen times with the original RGB values, except it is implemented as a single atomic colormap operation — it frees all 16 current color pixels and reallocates them in one pass.

Build docs developers (and LLMs) love