Every LWXGL application begins withDocumentation 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.
CreateWindow and ends with TerminateWindow. These three functions together manage the full lifetime of the X11 window: CreateWindow opens the display connection and allocates all required resources, DeleteWindow initiates a graceful close (honouring any registered callback), and TerminateWindow performs the final teardown once the main loop has exited.
CreateWindow
XOpenDisplay, allocates the 16-color palette from the default colormap, creates the application window and a matching back-buffer Pixmap, loads the default 9x15 bitmap font, and maps the window to the screen. The window is fixed-size by default (min/max size hints are set to w × h). The cursor is initialized to glyph 68 (the standard X11 crosshair).
Width of the window in pixels.
Height of the window in pixels. When scroll mode is active (see
ReserveScroll), the back-buffer height uses the reserved virtual canvas height instead.Window title string set via
XStoreName. The pointer only needs to be valid for the duration of the call.Palette index (0–15, or
CLR_* constant) used as the background fill color when clearing the back-buffer at the start of each frame.Return values
| Value | Meaning |
|---|---|
0 | Success. |
1 | XOpenDisplay failed — no X11 display available (DISPLAY not set or compositor not running). |
2 | Default font 9x15 could not be loaded. |
3 | A window already exists; CreateWindow is a no-op when called twice. |
127 + i | Color allocation failed for palette index i during XAllocColor. All previously allocated colors are freed before returning. |
TerminateWindow
CreateWindow and accumulated during the session. The teardown order is:
- Releases the OpenGL context by calling
ChangeGLXContext(-1). - Frees all live elements (calls
DeleteElementon each non-NULL slot). - Deletes all TGA allocations registered with
AllocateTGA. - Frees any active modal state message buffer.
- Frees the font (
XFreeFont), GC (XFreeGC), back-buffer pixmap (XFreePixmap), and all 16 colormap entries (XFreeColors). - Destroys the window (
XDestroyWindow) and closes the display connection (XCloseDisplay).
DeleteWindow
EventAttachDelete callback has been registered:
- With callback: The registered function is called. Its return value is assigned directly to the internal closing flag. If it returns 0, the close is cancelled and the main loop continues running. If it returns any non-zero value, the closing flag is set.
- Without callback: The closing flag is set immediately.
MainWindowLoop exits after completing the current frame.
Complete example
DeleteWindow is called internally by the X11 WM_DELETE_WINDOW protocol handler when the user clicks the window’s close button, so you do not need to call it yourself to handle normal close events.