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-color indexed palette (slots 0–15) that is allocated as X11 colors when the window is first created via GCreateWindow. Every color argument throughout the API — for text, buttons, rectangles, image primitives, and checkboxes — is an index into this palette rather than a direct RGB value. The palette functions let you read current color values from the X server, replace individual slots at runtime, and restore all slots to their built-in defaults.
Modifying a palette slot affects every rendered element that references that color index — including text labels, buttons, rect fills, checkbox colors, and every pixel in every image buffer that stores that index. Changes take effect globally and immediately across the entire window.

Default Palette

The table below lists the 16 built-in colors as defined in the library source. These values are 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
Palette index 0 (black) is also used as the “transparent” color by GPrimitiveSprite for . pixels. Modifying slot 0 will affect both the background color treatment in sprites and any element that explicitly references index 0.

GPaletteQuery

void GPaletteQuery(int idx, unsigned char* r, unsigned char* g, unsigned char* b);
Reads the current RGB values for palette slot idx by querying the X server’s colormap directly. The returned values reflect whatever color is currently allocated in that slot — which may differ from the built-in defaults if GPaletteModify has been called. Values are written to the caller-supplied output pointers.
idx
int
required
Palette slot to query (0–15).
r
unsigned char*
required
Output pointer that receives the red component (0–255).
g
unsigned char*
required
Output pointer that receives the green component (0–255).
b
unsigned char*
required
Output pointer that receives the blue component (0–255).

GPaletteModify

void GPaletteModify(int idx, unsigned char r, unsigned char g, unsigned char b, int redraw);
Replaces the X11 color allocation for palette slot idx with a new RGB value. Internally, the function frees the existing pixel allocation for that slot from the X server’s colormap and allocates a fresh one for the supplied r, g, b values. The updated pixel value is stored in the library’s internal colors[idx] array and will be used for all subsequent rendering of that palette index. If redraw is set to 1, GRedrawAllImages() is called automatically after the update, which forces all image elements to re-flush their pixel buffers to the screen with the new color. Set redraw to 0 if you are batch-modifying multiple slots and want to trigger the redraw yourself at the end.
idx
int
required
Palette slot to modify (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
Pass 1 to call GRedrawAllImages() immediately after the color change. Pass 0 to skip the automatic redraw.

GPaletteReset

void GPaletteReset();
Frees all 16 currently allocated X11 colors from the default colormap and reallocates them from the library’s built-in default palette values (see the table above). After all slots have been restored, GRedrawAllImages() is called unconditionally to refresh every image element on screen. This function takes no parameters and has no return value.

Code Example

/* Read the current value of palette slot 1 */
unsigned char r, g, b;
GPaletteQuery(1, &r, &g, &b);

/* Replace dark blue (index 1) with teal, redraw images immediately */
GPaletteModify(1, 0, 140, 180, 1);

/* Later, restore all 16 slots to their built-in defaults */
GPaletteReset();

Build docs developers (and LLMs) love