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.
MainWindowLoop is the heart of every LWXGL application. Once called, it takes ownership of the calling thread and drives all event processing, element rendering, and scheduled task execution at the requested frame rate until the window close flag is set. It returns only after the final frame that detects the closing condition.
MainWindowLoop
Target frame rate in frames per second (e.g.
60). The frame period is computed as 1 000 000 / target_fps microseconds. There is no upper-bound enforcement; setting a very high value reduces sleep time but does not disable the sleep logic entirely.Callback invoked once per rendered frame. Pass
NULL if no per-frame callback is needed.tick— zero-based frame counter that increments by 1 each rendered frame.delta_time— seconds elapsed since the previous rendered frame, cast tofloat. Use this for frame-rate-independent animation and physics.
Frame cycle
Each rendered frame executes the following steps in order:- Handle X11 events — all queued
XEventmessages (pointer motion, button press/release, key press/release, resize, delete-window, etc.) are drained and dispatched. - Render frame — the back-buffer is cleared, then
on_everyand element rendering are interleaved according to the rendering order set bySetRenderingOrder:ORDER_ELEM_SECOND(default,0):on_everyis called before elements are rendered to the back-buffer.ORDER_ELEM_FIRST(1): elements are rendered to the back-buffer beforeon_everyis called. The completed back-buffer is then copied to the window withXCopyArea.
- Process queued tasks — tasks registered with
NewQueuedTaskwhosetarget_timehas been reached are executed. Tasks withTASK_RUN_EVERYare re-queued automatically. - Sleep — if the remaining frame time is greater than 2 ms, the loop sleeps for
(remaining − 1 ms); otherwise it yields immediately withstd::this_thread::yield().
Exit condition
The loop exits when the internal closing flag is set. The flag is set byDeleteWindow (either directly, or via the WM_DELETE_WINDOW protocol handler and the EventAttachDelete callback). After the loop exits, the caller is responsible for calling TerminateWindow.
The
tick counter is an unsigned long long internally but is passed to on_every as a plain int. For very long-running sessions (over ~2 billion frames at 60 FPS ≈ ~1.1 years of continuous uptime) the value will wrap. In practice this is not a concern.