Skip to content

Window Overview

The Window module creates the OS window, establishes the graphics context (OpenGL or Vulkan), and processes hardware input. It serves as the bridge between the operating system and the engine's rendering and event systems.

Architecture

Input System

The Window owns Keyboard and Mouse instances and provides two ways to handle input:

Event-Based - React to input changes immediately via GLFW callbacks:

Polling - Check the current state of a key or mouse delta each frame:

Event Flow

Frame Timing

The Time singleton tracks delta time using glfwGetTime(), providing a consistent clock for systems regardless of frame rate:

Key Responsibilities

  • Window Lifecycle - Manage the creation, update loop, and termination of the native window.
  • Context Initialization - Bring up the OpenGL/Vulkan context via GLFW and GLAD.
  • Input State - Track keyboard and mouse states for frame-by-frame polling.
  • Event Generation - Convert GLFW callbacks into engine events.
  • Buffer Management - Handle swap buffers and vsync.

Construction

cpp
// Create a window via the static factory:
static Ref<Window> create(WindowID &id, std::string &title, int &width, int &height, bool headless);

The headless flag suppresses the window and skips input callback registration, enabling offscreen rendering or server-side execution.

For detailed implementation, see Window.