Window
This class creates and manages the operating system window, the graphics context, and propagates input events from the OS. It is typically constructed and controlled by the Application runtime, but can also be used directly in manual setups.
vglx::Window window({
.title = "My App",
.width = 1920,
.height = 1080,
.antialiasing = 4,
.vsync = true
});
auto ok = window.Initialize();
if (!ok) {
HandleError(ok.error());
}Construction
Constructors
Window()
Constructs a window.
Resources are not created until Initialize is called.
Window::Window(const Window::Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the window. |
Types
Window::Parameters struct
Parameters for constructing a Window object.
| Parameter | Description |
|---|---|
| title std::string | Window title. |
| width int | Client-area width in pixels. |
| height int | Client-area height in pixels. |
| antialiasing int | Anti-aliasing sample count. |
| vsync bool | Enable or disable vertical sync. |
ResizeCallback typedef
Function signature for window-resize notifications.
The callback is invoked when the window’s client-area size changes. Use the provided sizes to update viewports and camera projection.
using ResizeCallback = std::function<void(const ResizeParameters& params)>Functions
AspectRatio() float
Returns the aspect ratio (width / height).
float Window::AspectRatio() const;BeginUIFrame() void
Marks the beginning of a new UI frame.
Must be called before issuing any UI commands. If no UI system is active, this is a no-op.
void Window::BeginUIFrame();EndUIFrame() void
Marks the end of the current UI frame.
Must be called after all UI commands have been issued. If no UI system is active, this is a no-op.
void Window::EndUIFrame();FramebufferHeight() int
Returns the current framebuffer height in pixels.
On high-DPI displays this may differ from Height.
int Window::FramebufferHeight() const;FramebufferWidth() int
Returns the current framebuffer width in pixels.
On high-DPI displays this may differ from Width.
int Window::FramebufferWidth() const;Height() int
Returns the current logical window height in pixels.
int Window::Height() const;Initialize() std::expected<void, std::string>
Initializes the underlying OS window and graphics context.
std::expected<void, std::string> Window::Initialize();OnResize() void
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 high-DPI displays. The callback receives both logical window sizes and the framebuffer sizes in physical pixels.
void Window::OnResize(ResizeCallback callback);| Parameter | Description |
|---|---|
| callback | A function to invoke on resize with the new sizes. |
PollEvents() void
Processes pending window and input events.
Polls the operating system for events such as input, window resize, or close requests. Must be called at the top of the main loop to keep the application responsive.
void Window::PollEvents();RequestClose() void
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.
void Window::RequestClose();SetTitle() void
Updates the window title.
void Window::SetTitle(std::string_view title);| Parameter | Description |
|---|---|
| title | UTF-8 string to display in the window title bar. |
ShouldClose() bool
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.
bool Window::ShouldClose();SwapBuffers() void
Swaps the front and back buffers.
Presents the rendered frame to the display.
void Window::SwapBuffers();Width() int
Returns the current logical window width in pixels.
int Window::Width() const;