By the end of this guide you will have a working X11 window containing a text label and a clickable button. You will understand how to register elements by ID, attach an event callback, and run the frame loop — the three concepts that underpin every LWXGL application. No prior Xlib knowledge is required.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.
Complete Example
Save the following file ashello.c:
Compile and Run
Button clicked! to stdout. Close the window to exit.
How the Loop Works
MainWindowLoop is a blocking call that drives the entire application lifecycle. Internally, each iteration:
- Processes X11 events — mouse moves, button presses, key presses, and the window-close protocol are all dispatched here. If a mouse click lands inside a button’s bounding box, the button’s
onclickcallback is invoked immediately. - Calls
on_every(if non-NULL) — your per-frame callback receives the current tick counter (int) and the delta time since the last frame in seconds (float). This is where you would update game state, callImmediate*drawing functions, or modify element properties. - Renders all visible elements onto the back-buffer pixmap in their registered order, then blits the finished frame to the visible window in one atomic operation.
- Sleeps for the remainder of the frame budget so that CPU usage scales with
target_fpsrather than spinning at 100%.
MainWindowLoop returns, call TerminateWindow to free every element, release the 16 allocated Xlib colors, destroy the back-buffer pixmap, and close the display connection.
Element IDs are global. If you call
CreateButton(0, ...) and later CreateText(0, ...), the second call overwrites element slot 0 without warning. Use distinct IDs for every element in your application.Next Steps
Window Management
Learn the full
CreateWindow return codes, SetWindowTitle, EnableResizing, scrolling, and the modal dialog API.Elements
Explore every retained element type: buttons, inputs, images, consoles, checkboxes, OpenGL surfaces, and more.
Color Palette
Understand the 16-color palette, all
CLR_* constants, and how to customise colors at runtime with PaletteModify.Events
Attach keyboard and mouse callbacks, query real-time input state, and handle window-close events gracefully.