This guide walks you through building a minimal LWXGL application: a 400×300 window containing a text label and a button. When the button is clicked the label text updates in place — no rebuild required, just a live in-process element swap. By the end you will have a working binary that runs at 60 FPS using LWXGL’s built-in frame-capped loop.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.
Install LWXGL
Clone the repository and run the two Makefile targets to compile and install the shared library:
make build compiles libLWXGL.so in the repository root. make install copies it to /usr/local/lib, copies src/libLWXGL.h to /usr/local/include, and runs ldconfig so the dynamic linker picks up the new library immediately. See Build and Install LWXGL from Source for full details.Create your source file
Create a file called The program creates two elements — ID
hello.c with the following contents:0 (text) and ID 1 (button) — before entering the loop. on_click calls GCreateText again with the same ID 0, which replaces the existing label in-place.Compile
Link against both Because
libLWXGL and libX11:make install ran ldconfig, the linker can resolve -lLWXGL without any extra -L flags. If you skipped the install step you can point the linker at the repository directory directly:Run
Launch the compiled binary:A 400×300 window titled Hello LWXGL will appear. Click the Click me button and watch the label change from white “Click the button!” to green “Button clicked!”. Close the window normally — the WM close event is handled by LWXGL and exits the loop cleanly.
Tip: Press F12 while the window is open to toggle the built-in debug overlay, which displays live FPS and average per-frame work time.
Color parameters throughout the LWXGL API are palette indices in the range
0–15, not RGB values. The default 16-color palette is fixed at startup and maps to CGA-style colors (0 = Black, 7 = Light Gray, 10 = Light Green, 15 = White, and so on).For functions that take a packed color byte — such as the u, hvr, and p arguments of GCreateButton — each byte encodes two palette indices: the high nibble (bits 7–4, extracted with the H(byte) macro defined in main.cc) carries one color and the low nibble (bits 3–0, extracted with L(byte)) carries the other. For example, 0x87 means high nibble 8 (Dark Gray) and low nibble 7 (Light Gray).