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 color palette, initialized from the color_palette[] table in main.cc when GCreateWindow is called. Every color reference throughout the library — element colors, primitive drawing colors, image pixel values — is a palette index from 0 to 15. The Palette API lets you read back the current RGB value of any entry, replace an entry with new RGB values, and restore all entries to their defaults.
Modifying a palette entry affects the appearance of all elements and image canvases that reference that color index — not just future draws. A call to GPaletteModify or GPaletteReset with redraw != 0 will immediately repaint every image element on screen to reflect the updated colors.

GPaletteQuery

void GPaletteQuery(int idx, unsigned char* r, unsigned char* g, unsigned char* b);
Queries the current RGB components of palette entry idx by calling XQueryColor on the X11 colormap. The result reflects the color as actually allocated in the X server, which is scaled back from the 16-bit X11 representation.
idx
int
Palette entry index to query (0–15).
r
unsigned char*
Receives the red component of the color (0–255).
g
unsigned char*
Receives the green component of the color (0–255).
b
unsigned char*
Receives the blue component of the color (0–255).
unsigned char r, g, b;
GPaletteQuery(4, &r, &g, &b);
printf("Palette[4] = rgb(%d, %d, %d)\n", r, g, b);
// Default output: Palette[4] = rgb(186, 6, 6)

GPaletteModify

void GPaletteModify(int idx, unsigned char r, unsigned char g, unsigned char b, int redraw);
Replaces palette entry idx with the given RGB values. The old X11 color allocation for that index is freed and a new one is allocated. If redraw is non-zero, GRedrawAllImages() is called after the update so that image canvases immediately reflect the new color.
idx
int
Palette entry index to modify (0–15).
r
unsigned char
New red component (0–255).
g
unsigned char
New green component (0–255).
b
unsigned char
New blue component (0–255).
redraw
int
Pass a non-zero value to call GRedrawAllImages() immediately after updating the palette entry. Pass 0 to defer the visual update (useful when modifying several palette entries in one go — call GRedrawAllImages() manually once at the end).
// Replace Dark Red (index 4) with a bright orange, then redraw
GPaletteModify(4, 255, 140, 0, 1);

// Batch-modify several entries without a redraw after each one
GPaletteModify(1, 0, 0, 200, 0);
GPaletteModify(9, 100, 100, 255, 0);
GRedrawAllImages(); // One redraw for all changes

GPaletteReset

void GPaletteReset(void);
Restores all 16 palette entries to their factory default values (defined in the color_palette[] array in main.cc). All existing X11 color allocations are freed first, then re-allocated from the defaults. Calls GRedrawAllImages() automatically after the reset.
// Undo any runtime palette changes and force a full repaint
GPaletteReset();

GRedrawAllImages

void GRedrawAllImages(void);
Iterates every element slot and, for each image element, invalidates its shadow (previous-frame) buffer and calls GUpdateImage to force a complete pixel-by-pixel repaint using the current palette. Typically called internally by GPaletteModify (when redraw != 0) and GPaletteReset, but may also be called manually whenever a full image refresh is needed.
// Manually trigger a full repaint of all image canvases
GRedrawAllImages();

Default Palette

The following table shows the 16 default palette entries as defined in color_palette[] in main.cc. These are the values restored by GPaletteReset.
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

Build docs developers (and LLMs) love