Window
The Window class creates the OS window and manages the framebuffer. It is typically managed by the Application runtime, but can also be constructed directly for manual initialization flows.
Typical usage:
vglx::Window window({
.title = "My App",
.width = 1280,
.height = 720,
.antialiasing = 4,
.vsync = true
});
auto ok = window.Initialize();
if (!ok) {
HandleError(ok.error());
}
Construction
Constructors
Window()
vglx::Window::Window(const Window::Parameters ¶ms)
Parameter | Description |
---|---|
params | Window::Parameters |
Constructs a window object with the given parameters. The window resources are not created until Initialize is called.
Types
Window::Parameters struct
Construction parameters for Window.
Name | Type | Description |
---|---|---|
antialiasing | int | Multisample anti-aliasing sample count. |
height | int | Client-area height in pixels. |
title | std::string | Window title string. |
vsync | bool | Enable or disable vertical sync. |
width | int | Client-area width in pixels. |
Functions
AspectRatio() float
float vglx::Window::AspectRatio() const
Returns the logical aspect ratio (width / height).
BeginUIFrame() void
void vglx::Window::BeginUIFrame()
Marks the beginning of a new UI frame. Call this once per frame before issuing any UI commands. If no UI system is active, this is a no-op.
EndUIFrame() void
void vglx::Window::EndUIFrame()
Marks the end of the current UI frame. Call this once per frame after all UI commands have been issued. If no UI system is active, this is a no-op.
FramebufferHeight() int
int vglx::Window::FramebufferHeight() const
Returns the current framebuffer height in pixels. On HiDPI displays this may differ from Height.
FramebufferWidth() int
int vglx::Window::FramebufferWidth() const
Returns the current framebuffer width in pixels. On HiDPI displays this may differ from Width.
Height() int
int vglx::Window::Height() const
Returns the current logical window height in pixels.
Initialize() std::expected< void, std::string >
std::expected< void, std::string > vglx::Window::Initialize()
Initializes the underlying OS window and graphics context.
OnResize() void
void vglx::Window::OnResize(ResizeCallback callback)
Parameter | Description |
---|---|
callback | None |
Registers a callback to be invoked when the window is resized. The callback is executed whenever the client-area dimensions change, including user drag-resizes and OS-driven scaling changes on HiDPI displays. The callback receives both logical window sizes and the framebuffer sizes in physical pixels.
PollEvents() void
void vglx::Window::PollEvents()
Processes pending window and input events. Polls the operating system for events such as input, window resize, or close requests. Must be called regularly to keep the window responsive.
RequestClose() void
void vglx::Window::RequestClose()
Requests that the window be closed. Sets the internal close flag so that ShouldClose returns true. This allows the application to exit the main loop gracefully.
SetTitle() void
void vglx::Window::SetTitle(std::string_view title)
Parameter | Description |
---|---|
title | UTF-8 string to display in the window title bar. |
Updates the window title string.
ShouldClose() bool
bool vglx::Window::ShouldClose()
Returns whether the window has been flagged for closing. This flag is set when the user requests the window to close through the operating system or when RequestClose is called.
SwapBuffers() void
void vglx::Window::SwapBuffers()
Swaps the front and back buffers. Presents the rendered frame to the display. Should be called once per frame after rendering and UI submission.