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-color palette (indices 0–15) for all rendering. Widgets, drawing primitives, and image canvases all reference palette indices rather than raw RGB values. This means changing a single palette entry instantly recolors every element that uses that index — you can retheme an entire UI by swapping a handful of entries.
Image canvas pixels (via GGetImageData) store palette indices, not RGB values. Modifying a palette entry at runtime changes the apparent color of every pixel on every canvas that was painted with that index — without needing to redraw the canvas content.

Default Palette

The 16 default colors are allocated from the X11 colormap during GCreateWindow. They approximate the classic CGA/VGA color set:
IndexNameRGB
0Black000
1Dark Blue33173
2Dark Green01700
3Dark Cyan0168168
4Dark Red18666
5Dark Magenta1680168
6Orange23012634
7Light Gray168168168
8Dark Gray858783
9Light Blue8787255
10Light Green8525585
11Light Cyan96240240
12Light Red2558585
13Light Magenta24084240
14Yellow24424254
15White255255255

Querying a Color

void GPaletteQuery(int idx, unsigned char* r, unsigned char* g, unsigned char* b);
Fills r, g, and b with the current RGB values for palette entry idx. The values are read back from the X11 colormap via XQueryColor, so they reflect any modifications made with GPaletteModify.
unsigned char r, g, b;
GPaletteQuery(4, &r, &g, &b);
printf("Palette[4] = rgb(%d, %d, %d)\n", r, g, b);
/* Output: Palette[4] = rgb(186, 6, 6) */

Modifying a Color

void GPaletteModify(int idx, unsigned char r, unsigned char g, unsigned char b, int redraw);
ParameterDescription
idxPalette index to replace (0–15).
r, g, bNew RGB values (0–255 each).
redrawIf non-zero, calls GRedrawAllImages() to immediately update all image canvases. Widget colors (buttons, text, etc.) update on the next GRenderWindow() call without needing redraw.
Internally, the existing X11 color cell is freed with XFreeColors and a new one is allocated with XAllocColor at the same colors[idx] slot.
/* Remap index 4 from dark red to a custom orange-red */
GPaletteModify(4, 220, 60, 20, 1);

/* Remap index 0 (background) to a dark navy blue */
GPaletteModify(0, 15, 15, 45, 0); /* no canvas redraw needed for background */
GPaletteModify does not force a full window redraw on its own. Widget and background color changes take effect on the next GRenderWindow() call. Pass redraw=1 only when you have image canvases that need to reflect the new color immediately.

Resetting the Palette

void GPaletteReset(void);
Restores all 16 palette entries to their factory defaults (the values in the table above). Frees all 16 current X11 color cells with a single XFreeColors call, then reallocates all 16 from scratch. Automatically calls GRedrawAllImages() to refresh canvases.
/* Undo all palette customizations */
GPaletteReset();

Packed Color Parameters

Many widget creation functions accept packed color bytes for their appearance parameters. A packed color byte encodes two palette indices in a single int:
  • Upper nibble (bits 4–7): border or outline color index.
  • Lower nibble (bits 0–3): fill or background color index.
int packed = (border_color << 4) | fill_color;
Functions that use packed colors:
FunctionPacked Parameters
GCreateButtonu (unpressed), hvr (hover), p (pressed)
GCreateInputu (inactive), hvr (active/hover)
GCreateCheckboxcb_col (checkbox square)
GCreateConsolecon_clr (console background)
/* border = 7 (light gray), fill = 8 (dark gray) */
int panel_color = (7 << 4) | 8; /* = 0x78 */

/* border = 15 (white), fill = 1 (dark blue) */
int highlight = (15 << 4) | 1;  /* = 0xF1 */

GCreateButton(1, 100, 100, 120, 28,
    panel_color,   /* idle     */
    highlight,     /* hover    */
    (0 << 4) | 15, /* pressed: black border, white fill */
    "Click me", NULL);
Color index values for packed bytes must fit in a nibble (0–15), which matches exactly the 16 entries in the LWXGL palette.

Build docs developers (and LLMs) love