Skip to content

Window

Cross-platform application 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:

cpp
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()

cpp
vglx::Window::Window(const Window::Parameters &params)
ParameterDescription
paramsWindow::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.

NameTypeDescription
antialiasingintMultisample anti-aliasing sample count.
heightintClient-area height in pixels.
titlestd::stringWindow title string.
vsyncboolEnable or disable vertical sync.
widthintClient-area width in pixels.

Functions

AspectRatio() float

cpp
float vglx::Window::AspectRatio() const

Returns the logical aspect ratio (width / height).

BeginUIFrame() void

cpp
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

cpp
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

cpp
int vglx::Window::FramebufferHeight() const

Returns the current framebuffer height in pixels. On HiDPI displays this may differ from Height.

FramebufferWidth() int

cpp
int vglx::Window::FramebufferWidth() const

Returns the current framebuffer width in pixels. On HiDPI displays this may differ from Width.

Height() int

cpp
int vglx::Window::Height() const

Returns the current logical window height in pixels.

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

cpp
std::expected< void, std::string > vglx::Window::Initialize()

Initializes the underlying OS window and graphics context.

OnResize() void

cpp
void vglx::Window::OnResize(ResizeCallback callback)
ParameterDescription
callbackNone

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

cpp
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

cpp
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

cpp
void vglx::Window::SetTitle(std::string_view title)
ParameterDescription
titleUTF-8 string to display in the window title bar.

Updates the window title string.

ShouldClose() bool

cpp
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

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

Width() int

cpp
int vglx::Window::Width() const

Returns the current logical window width in pixels.

Released under the MIT License.