Every LWXGL application follows the same three-phase lifecycle: create a window and allocate X11 resources, loop to process events and render frames, then terminate to release everything cleanly. Understanding each phase helps you structure your application correctly and avoid resource leaks.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.
Creating a Window
GCreateWindow opens a connection to the X display, loads the font, allocates the 16-color palette, creates the window and a back-buffer pixmap, and sets fixed size hints so the user cannot resize the window.
| Parameter | Description |
|---|---|
w | Window width in pixels |
h | Window height in pixels |
name | Title bar string |
bgcol | Background palette index (0–15) used to clear the window each frame |
| Code | Meaning |
|---|---|
0 | Success |
1 | Could not open X display ($DISPLAY not set, or no X server running) |
2 | Required font 9x15 could not be loaded |
3 | A window is already open |
w × h, preventing the user from resizing it.
The Simple Loop
GSimpleWindowLoop is the recommended way to drive your application. It manages frame timing, calls event handling and rendering automatically each frame, and invokes your callback once per tick.
| Parameter | Description |
|---|---|
target_fps | Desired frames per second (e.g. 60) |
on_every | Called once per frame with the current tick counter (starts at 0, increments by 1 each frame). May be NULL. |
Check frame timing
Waits until at least
1 000 000 / target_fps microseconds have elapsed since the last frame. If the system falls more than two frame-periods behind, the clock is reset to prevent a backlog.Manual Loop
If you need finer control over timing — for example, to integrate a physics engine with a fixed timestep — you can drive the loop yourself usingGWindowShouldClose, GHandleWindowEvents, and GRenderWindow.
The debug overlay (F12) is only active when
GSimpleWindowLoop is used, because it requires the frame-time measurements that the simple loop collects. In a manual loop, pressing F12 will toggle the overlay flag but no overlay will be drawn.Window Close
Two functions can trigger a close:GDeleteWindow()
Signals that the window should close by setting the internal
closing flag to 1. If a GEventAttachDelete callback has been registered, that callback’s return value determines whether the close actually proceeds — return non-zero to allow it, zero to cancel it.Ctrl + Escape
Invokes
GDeleteWindow() directly, bypassing the key callback. The GEventAttachDelete callback is still checked — return 0 from it to cancel the close.GWindowShouldClose() returns 1), call GTerminateWindow() to release all resources:
GTerminateWindow frees every registered element, releases the GC, back-buffer pixmap, stipple pixmap, font, and allocated X colors, then destroys the window and closes the display connection.
Debug Overlay
Press F12 at any time whileGSimpleWindowLoop is running to toggle the debug overlay. The overlay renders a small black box in the top-left corner of the window showing:
| Metric | Description |
|---|---|
| FT | Average frame work time in microseconds, rolling average over the last 60 frames |
| FPS | Instantaneous frames per second |