Skip to main content

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.

LWXGL has two built-in overlay features: modal dialogs that block normal widget interaction while they are visible, and a debug overlay that shows real-time performance metrics during development.
void GSpawnModal(int type, const char* msg, void (*on_confirm)());
Displays a centered dialog box with a message and one or two buttons.
typeButtons shown
0OK only (info dialog)
1OK + Cancel (confirm dialog)
msg is the message string displayed inside the dialog. It supports \n for line breaks; each line is rendered with the built-in 9×15 font, so keep lines to roughly 31 characters or fewer to fit within the dialog box. on_confirm is a void callback invoked when the user clicks OK. Pass NULL to have OK simply dismiss the dialog. The Cancel button (type 1 only) always dismisses the dialog without calling any callback. While a modal is open:
  • All widget button and checkbox clicks are suppressed.
  • The keyboard callback registered with GEventAttachKey is not invoked.
  • The mouse-click callback registered with GEventAttachClick is not invoked.

Info Dialog

// Show a simple notification — OK dismisses it
GSpawnModal(0, "File saved successfully.", NULL);

Confirm Dialog

void on_confirm(void) {
    printf("User confirmed!\n");
    // perform the destructive action here
}

// Inside a button callback:
GSpawnModal(1, "Are you sure?\nThis cannot be undone.", on_confirm);

Querying Modal State

int GQueryModalOpen(void);
Returns 1 if a modal is currently visible, 0 otherwise. Use this to pause game logic, animations, or any per-frame work that should not run while the user is reading a dialog.
void on_frame(int tick) {
    if (GQueryModalOpen()) return; // pause all game logic

    // ... normal per-frame update ...
}

Combining Modals with Window Close

A common pattern is to spawn a confirmation modal when the user tries to close the window, and perform the actual close inside the on_confirm callback:
void do_close(void) {
    GDeleteWindow(); // allow the window to close now
}

int on_close(void) {
    GSpawnModal(1, "Quit the application?\nUnsaved changes will be lost.", do_close);
    return 0; // cancel the close — do_close() will handle it
}

// Registered before the loop:
GEventAttachDelete(on_close);

Debug Overlay

When you run your application loop with GSimpleWindowLoop, the debug overlay is enabled automatically. Press F12 at runtime to toggle its visibility. The overlay is drawn in the top-left corner as a black box with a white border and two lines of white text:
LineFormatMeaning
1FT: N (us)Average frame time in microseconds, averaged over the last 60 frames
2FPS: N.NCurrent frames per second
The frame time (FT) measures the time spent doing real work each frame (event handling, rendering, and your on_every callback), not the total wall-clock time between frames. It is useful for spotting expensive draw calls or callback logic.
The debug overlay is only available when using GSimpleWindowLoop. If you drive the loop manually with GHandleWindowEvents and GRenderWindow, the overlay infrastructure is never initialized and nothing is displayed.
F12 is reserved by LWXGL and cannot be used as a user key. The GEventAttachKey callback is never called for F12 — LWXGL intercepts it internally to toggle the debug overlay before the callback dispatch runs.

Full Example

#include "libLWXGL.h"
#include <stdio.h>

static int running = 1;

void on_delete_confirmed(void) {
    GDeleteWindow();
}

int on_close(void) {
    GSpawnModal(1, "Are you sure you want to quit?", on_delete_confirmed);
    return 0; // defer actual close to on_delete_confirmed
}

void on_frame(int tick) {
    if (GQueryModalOpen()) return; // pause while dialog is visible

    // Normal per-frame logic here...
}

int main(void) {
    GCreateWindow(640, 480, "Modal Demo", 8);

    GCreateText(0, 20, 20, 15,
        "Press F12 to toggle the debug overlay.\n"
        "Close the window to see the confirm dialog.");

    GEventAttachDelete(on_close);
    GSimpleWindowLoop(60, on_frame);
    GTerminateWindow();
    return 0;
}

Build docs developers (and LLMs) love