LWXGL provides a small set of utility functions that complement the core windowing and drawing APIs.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.
GetElapsedTime gives a reliable monotonic clock tied to the main loop for animations and timing logic. NewQueuedTask lets you schedule one-shot or repeating callbacks without managing external timers. SpawnModal presents a blocking overlay dialog for alerts, confirmations, and text input. QueryModalOpen and QueryScroll allow you to adapt per-frame logic to modal and scroll state without relying on callbacks.
GetElapsedTime
Returns the total number of seconds elapsed since MainWindowLoop started.
std::chrono::steady_clock timestamps. It starts at 0.0 at the first frame and grows monotonically. It is safe to call from within on_every, from task callbacks, or from event callbacks. Because the value accumulates whole-frame deltas, it advances in discrete frame-sized steps rather than continuously — two calls within the same frame return the same value.
Returns: double — seconds since MainWindowLoop was first called.
NewQueuedTask
Schedules a deferred or repeating void callback.
on_every returns. When GetElapsedTime() reaches or exceeds the task’s target_time, the task function is called with no arguments. One-shot tasks (TASK_RUN_AFTER) are discarded after execution. Repeating tasks (TASK_RUN_EVERY) are re-queued with target_time += run_after so that subsequent firings drift-correct rather than accumulate latency.
For TASK_RUN_EVERY, the first target_time is computed as ceil(elapsed_time / run_after) * run_after, which aligns the first firing to the next clean multiple of run_after rather than elapsed_time + run_after. This prevents gradually drifting repeating tasks.
Task scheduling mode. See the constants table below.
For
TASK_RUN_AFTER: seconds to wait before the single execution. For TASK_RUN_EVERY: interval in seconds between repeated executions.Pointer to a
void callback() function with no parameters to invoke when the task fires.Task type constants
| Constant | Value | Behavior |
|---|---|---|
TASK_RUN_AFTER | 0 | Run task once, run_after seconds from now, then discard. |
TASK_RUN_EVERY | 1 | Run task repeatedly every run_after seconds, ceil-aligned start. |
Tasks are evaluated sequentially in the order they fire within a single frame. If multiple tasks become ready in the same frame they are all executed before the next frame begins.
SpawnModal
Displays a blocking modal overlay dialog.
EventAttachKey callback, and the EventAttachClick callback are all suppressed while the modal is open. The modal is dismissed when the user clicks the OK button (and, for non-alert types, an optional Cancel button). When dismissed via OK, on_confirm is called with NULL for MODAL_ALERT and MODAL_CONFIRM, or with a pointer to the user’s typed input string for MODAL_INPUT.
The msg string is duplicated internally (strdup) — the caller does not need to keep it alive after the call returns.
Modal variant. See the constants table below.
Message text displayed in the modal body. Internally duplicated; may be a temporary buffer.
Callback invoked when the user clicks OK. For
MODAL_ALERT and MODAL_CONFIRM, input is NULL. For MODAL_INPUT, input points to the entered text (up to 150 characters). The pointer is only valid for the duration of the callback — copy the string if you need it later. Pass NULL if no action is needed on confirmation.Modal type constants
| Constant | Value | Description |
|---|---|---|
MODAL_ALERT | 0 | Single OK button. Used for informational notices. Cancel is disabled. |
MODAL_CONFIRM | 1 | Cancel + OK buttons. No text input. on_confirm is called only on OK. |
MODAL_INPUT | 2 | Text input field + Cancel + OK. on_confirm receives the typed string. |
QueryModalOpen
Returns whether a modal dialog is currently displayed.
1 if a modal spawned with SpawnModal is active, 0 otherwise. Useful inside on_every to pause animations or game logic while the user interacts with a dialog.
QueryScroll
Returns the current vertical scroll offset of the virtual back-buffer canvas.
CreateWindow is called via ReserveScroll. The scroll offset starts at 0 (top) and increases as the user scrolls down, capped at virtual_height − window_height. Always returns 0 when scroll mode is inactive.
Returns: Current scroll offset in pixels.