Skip to content

Window ​

Represents a cross-platform application window.

This class creates and manages the operating system window, the graphics context, and propagates input events from the OS. Construct one in your main, call Initialize, then drive it with PollEvents and SwapBuffers each frame.

cpp
vglx::Window window({
  .title = "My App",
  .width = 1920,
  .height = 1080,
  .antialiasing = 4,
  .vsync = true
});

auto ok = window.Initialize();
if (!ok) {
  HandleError(ok.error());
}

This class defines the windowing interface only. The actual implementation may be platform-specific or provided by an external dependency such as GLFW.

Construction ​

Constructors ​


Window() ​

Constructs a window.

Resources are not created until Initialize is called.

cpp
Window::Window(const Window::Parameters& params);
ParameterDescription
paramsInitialization parameters for constructing the window.

Types ​

Window::Parameters struct ​

Parameters for constructing a Window object.

ParameterDescription
title std::stringWindow title.
width intClient-area width in pixels.
height intClient-area height in pixels.
vsync boolEnable 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 camera projections and canvas layout.

cpp
using ResizeCallback = std::function<void(const ResizeParameters& params)>

Functions ​

AspectRatio() float ​

Returns the aspect ratio (width / height).

cpp
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.

cpp
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.

cpp
void Window::EndUIFrame();

FramebufferHeight() int ​

Returns the current framebuffer height in pixels.

On high-DPI displays this may differ from Height.

cpp
int Window::FramebufferHeight() const;

FramebufferWidth() int ​

Returns the current framebuffer width in pixels.

On high-DPI displays this may differ from Width.

cpp
int Window::FramebufferWidth() const;

Height() int ​

Returns the current logical window height in pixels.

cpp
int Window::Height() const;

Initialize() std::expected<void, std::string> ​

Initializes the underlying OS window and graphics context.

cpp
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. It is also invoked once with the initial size on the first PollEvents call, so size-dependent state can be fully initialized through this callback. The callback receives both logical window sizes and the framebuffer sizes in physical pixels.

cpp
void Window::OnResize(ResizeCallback callback);
ParameterDescription
callbackA function to invoke on resize with the new sizes.

operator=() Window& ​

cpp
Window& Window::operator=(Window&& ) noexcept;
ParameterDescription

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.

cpp
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.

cpp
void Window::RequestClose();

SetTitle() void ​

Updates the window title.

cpp
void Window::SetTitle(std::string_view title);
ParameterDescription
titleUTF-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.

cpp
bool Window::ShouldClose();

SwapBuffers() void ​

Swaps the front and back buffers.

Presents the rendered frame to the display.

cpp
void Window::SwapBuffers();

Width() int ​

Returns the current logical window width in pixels.

cpp
int Window::Width() const;

Released under the MIT License.