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 16-entry color palette shared by all rendering. Every color parameter accepted by widgets, drawing primitives, and image canvases is a palette index in the range 0–15. Modifying a palette entry at runtime recolors all elements and image pixels that reference that index — on the next GRenderWindow() call for widgets, and immediately for image canvases when the redraw flag is set.

GPaletteQuery

void GPaletteQuery(int idx, unsigned char* r, unsigned char* g, unsigned char* b);
Queries the current RGB values of a palette entry by asking X11 directly via XQueryColor. Because the result comes from the live X11 colormap allocation rather than a cached copy, it always reflects the most recent state — including any changes made by GPaletteModify.
idx
int
required
Palette index to query. Must be in the range 0–15.
r
unsigned char*
required
Output pointer. On return, receives the red component of the color (0–255).
g
unsigned char*
required
Output pointer. On return, receives the green component of the color (0–255).
b
unsigned char*
required
Output pointer. On return, receives the blue component of the color (0–255).
Example — query palette index 7 (default Light Gray):
unsigned char r, g, b;
GPaletteQuery(7, &r, &g, &b);
printf("Index 7 → R=%u G=%u B=%u\n", r, g, b);
/* Default output: Index 7 → R=168 G=168 B=168 */
The values returned by GPaletteQuery are divided by 257 from the underlying 16-bit X11 color components, so they are always in the 8-bit range 0–255 regardless of display depth.

GPaletteModify

void GPaletteModify(int idx, unsigned char r, unsigned char g, unsigned char b, int redraw);
Replaces a palette entry with a new RGB color. Internally, the old X11 color allocation for the slot is freed with XFreeColors and a fresh one is allocated with XAllocColor. All widgets that reference this index will render with the new color the next time GRenderWindow() is called — no extra step is required for widget elements. Image canvas pixels that use this index are only updated if redraw is non-zero.
idx
int
required
Palette index to replace. Must be in the range 0–15.
r
unsigned char
required
New red component (0–255).
g
unsigned char
required
New green component (0–255).
b
unsigned char
required
New blue component (0–255).
redraw
int
required
When non-zero, GRedrawAllImages() is called automatically after the palette entry is updated, refreshing all image canvases. Pass 0 to defer the redraw (e.g. when batching multiple palette changes before a single redraw).
GRenderWindow reads palette colors live on every frame, so widgets (buttons, text, rects, etc.) always pick up palette changes without needing GRedrawAllImages. Only image canvas pixel data — which is pre-rendered into pixmaps — requires a redraw pass.
Example — remap index 4 from default Dark Red to a custom teal color:
/* Replace Dark Red (186, 6, 6) with teal (0, 180, 160).
   Pass redraw=1 to immediately refresh any image canvases
   that reference palette index 4. */
GPaletteModify(4, 0, 180, 160, 1);

/* Widget elements (buttons, text, rects) using color index 4
   will display teal on the next GRenderWindow() call automatically. */
GRenderWindow();
GPaletteModify modifies the X11 colormap allocation. On pseudocolor (8-bit) displays with a limited, shared colormap, freeing and reallocating color cells can visibly affect other applications that share the same colormap. This is not a concern on modern TrueColor (24/32-bit) displays.

GPaletteReset

void GPaletteReset();
Restores all 16 palette entries to their factory default RGB values. All 16 current X11 color allocations are freed at once, then reallocated from the built-in color_palette table. GRedrawAllImages() is called automatically after the reset to refresh image canvas pixel data. Default palette:
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
Example — reset the palette after temporary modifications:
/* Apply some theme changes at runtime... */
GPaletteModify(0, 20, 20, 30, 0);
GPaletteModify(15, 220, 220, 235, 0);
GRedrawAllImages();

/* Later, restore the original CGA-style palette in one call. */
GPaletteReset();
GRenderWindow();
GPaletteReset is the cleanest way to undo a series of GPaletteModify calls. It resets all 16 entries atomically and triggers a single GRedrawAllImages pass, which is more efficient than calling GPaletteModify 16 times with redraw=1.

Build docs developers (and LLMs) love