Skip to main content

Overview

The Window class provides the main interface for interacting with the Atlas Engine. It manages window creation, rendering loops, scene management, and input handling.

WindowConfiguration

Structure representing the configuration options for creating a window.
title
std::string
The title of the window displayed in the title bar.
width
int
The width of the window in pixels.
height
int
The height of the window in pixels.
renderScale
float
default:"0.75f"
Internal rendering resolution scale factor. Values below 1.0 render at a lower resolution and upscale to the window, improving performance.
mouseCaptured
bool
default:"true"
Whether the mouse cursor should be captured and hidden.
posX
int
default:"WINDOW_CENTERED"
The X position of the window. Use WINDOW_CENTERED to center.
posY
int
default:"WINDOW_CENTERED"
The Y position of the window. Use WINDOW_CENTERED to center.
multisampling
bool
default:"true"
Whether to enable multisampling anti-aliasing.
decorations
bool
default:"true"
Whether the window should have decorations (title bar, borders).
resizable
bool
default:"true"
Whether the window can be resized by the user.
transparent
bool
default:"false"
Whether the window framebuffer should be transparent.
alwaysOnTop
bool
default:"false"
Whether the window should always stay on top of other windows.
opacity
float
default:"1.0f"
The opacity of the window. 1.0 is fully opaque, 0.0 is fully transparent.
aspectRatioX
int
default:"-1"
The width component of the aspect ratio. Use -1 for no constraint.
aspectRatioY
int
default:"-1"
The height component of the aspect ratio. Use -1 for no constraint.
ssaoScale
float
default:"0.5f"
Resolution scale used specifically for SSAO passes. Lower values reduce quality but greatly boost performance.

Window Class

Constructor

Window(const WindowConfiguration &config);
Constructs a window with the specified configuration.
config
const WindowConfiguration&
Window configuration settings.

Properties

title
std::string
The title of the window displayed in the title bar.
width
int
The width of the window in pixels.
height
int
The height of the window in pixels.
gravity
float
default:"9.81f"
The gravity constant applied to physics bodies. Default is 9.81 m/s².
audioEngine
std::shared_ptr<AudioEngine>
The audio engine instance for managing spatial audio. Shared across the window.
usesDeferred
bool
default:"false"
Whether the window is using deferred rendering.
mainWindow
static Window*
Static pointer to the main window instance. Used for global access to the primary window.

Core Methods

run

void run();
Starts the main window loop and begins rendering.

close

void close();
Closes the window and terminates the application.

setClearColor

void setClearColor(const Color &color);
Sets the background clear color for the window.
color
const Color&
The color to use for clearing the screen.

Fullscreen and Window Mode

setFullscreen

void setFullscreen(bool enable);
void setFullscreen(Monitor &monitor);
Sets the window to fullscreen mode.
enable
bool
True to enable fullscreen, false to disable.
monitor
Monitor&
The monitor to use for fullscreen.

setWindowed

void setWindowed(const WindowConfiguration &config);
Sets the window to windowed mode with new configuration.
config
const WindowConfiguration&
New window configuration.

enumerateMonitors

static std::vector<Monitor> enumerateMonitors();
Enumerates all available monitors.
return
std::vector<Monitor>
Vector of available monitors.

Scene and Camera Management

setCamera

void setCamera(Camera *newCamera);
Sets the camera for the window.
newCamera
Camera*
The camera to use for rendering. Must be long-lived.

setScene

void setScene(Scene *scene);
Sets the scene for the window.
scene
Scene*
The scene to render.

getCurrentScene

Scene* getCurrentScene();
Gets the current scene being rendered.
return
Scene*
Pointer to the current scene.

getCamera

Camera* getCamera();
Gets the current camera.
return
Camera*
Pointer to the current camera.

Object Management

addObject

void addObject(Renderable *object);
Adds a renderable object to the window.
object
Renderable*
The renderable object to add. The object must be long-lived.
The object must be long-lived. This means that declaring it as a class property is a good idea.

removeObject

void removeObject(Renderable *object);
Removes a renderable object from the window.

addPreferencedObject

void addPreferencedObject(Renderable *object);
Adds a renderable object with higher rendering priority.

addPreludeObject

void addPreludeObject(Renderable *object);
Adds a renderable object to be rendered first.

addUIObject

void addUIObject(Renderable *object);
Registers a UI renderable so it is drawn after world geometry.

addLateForwardObject

void addLateForwardObject(Renderable *object);
Adds a renderable to the late forward queue. Late forward renderables are evaluated after the main forward pass.

Input Handling

isKeyPressed

bool isKeyPressed(Key key);
Checks if a key is currently pressed.
key
Key
The key to check.
return
bool
True if the key is pressed, false otherwise.

isKeyClicked

bool isKeyClicked(Key key);
Checks if a key was clicked (pressed and released) this frame.
key
Key
The key to check.
return
bool
True if the key was clicked, false otherwise.

releaseMouse

void releaseMouse();
Releases mouse capture, allowing the cursor to move freely.

captureMouse

void captureMouse();
Captures the mouse cursor for camera control.

getCursorPosition

std::tuple<int, int> getCursorPosition();
Gets the current cursor position.
return
std::tuple<int, int>
X and Y cursor coordinates.

Timing

getTime

float getTime();
Gets the current time since window creation.
return
float
Time in seconds.

getDeltaTime

float getDeltaTime() const;
Gets the delta time between frames.
return
float
Delta time in seconds.

getFramesPerSecond

float getFramesPerSecond() const;
Gets the current frames per second.
return
float
Frames per second value.

Rendering Configuration

useDeferredRendering

void useDeferredRendering();
Enables deferred rendering for the window. This allows for more advanced lighting and post-processing effects.

getRenderScale

float getRenderScale() const;
Returns the active internal render scale.
return
float
The render scale factor.

getSSAORenderScale

float getSSAORenderScale() const;
Returns the SSAO-specific render scale.
return
float
The SSAO render scale factor.

enableSSR

void enableSSR(bool enabled = true);
Enables or disables screen-space reflections.

isSSREnabled

bool isSSREnabled() const;
Checks if screen-space reflections are enabled.

getSize

Size2d getSize();
Gets the framebuffer size of the window.
return
Size2d
The width and height of the framebuffer.

Debug Methods

activateDebug

void activateDebug();
Activates debug mode for the window.

deactivateDebug

void deactivateDebug();
Deactivates debug mode for the window.

setLogOutput

void setLogOutput(bool showLogs, bool showWarnings, bool showErrors);
Configures which log messages are displayed.

Advanced Rendering

getDevice

std::shared_ptr<opal::Device> getDevice() const;
Returns the opal device instance for rendering.
return
std::shared_ptr<opal::Device>
Pointer to the rendering device.

getGBuffer

RenderTarget* getGBuffer() const;
Returns the lazily created deferred geometry buffer.
return
RenderTarget*
Pointer to the G-buffer contents.

addRenderTarget

void addRenderTarget(RenderTarget *target);
Adds a render target to the window.
target
RenderTarget*
The render target to add.

Monitor Class

Class representing a monitor with video mode querying capabilities.

Properties

monitorID
int
The unique identifier for this monitor.
primary
bool
Whether this is the primary monitor.

Methods

queryVideoModes

std::vector<VideoMode> queryVideoModes() const;
Queries all available video modes for this monitor.
return
std::vector<VideoMode>
Vector of available video modes.

getCurrentVideoMode

VideoMode getCurrentVideoMode() const;
Gets the current video mode of this monitor.
return
VideoMode
The current video mode.

getPhysicalSize

std::tuple<int, int> getPhysicalSize() const;
Gets the physical size of the monitor in millimeters.
return
std::tuple<int, int>
Width and height in millimeters.

getPosition

std::tuple<int, int> getPosition() const;
Gets the position of the monitor in the desktop coordinate system.
return
std::tuple<int, int>
X and Y position coordinates.

getContentScale

std::tuple<float, float> getContentScale() const;
Gets the content scale factors for this monitor.
return
std::tuple<float, float>
Horizontal and vertical scale factors.

getName

std::string getName() const;
Gets the human-readable name of this monitor.
return
std::string
The monitor name.

VideoMode Structure

Structure representing a video mode with resolution and refresh rate.
width
int
The width of the video mode in pixels.
height
int
The height of the video mode in pixels.
refreshRate
int
The refresh rate in Hz.

Example Usage

// Create a window with specific configuration
WindowConfiguration config;
config.title = "My Game";
config.width = 1280;
config.height = 720;
config.renderScale = 0.75f;
config.multisampling = true;

Window window(config);

// Set up camera and scene
Camera camera;
Scene scene;
window.setCamera(&camera);
window.setScene(&scene);

// Add objects to the scene
CoreObject cube = createBox({1.0, 1.0, 1.0}, Color::red());
window.addObject(&cube);

// Configure rendering
window.useDeferredRendering();
window.setClearColor(Color(0.2f, 0.3f, 0.4f, 1.0f));

// Run the main window loop
window.run();

Monitor Example

// Enumerate all available monitors
std::vector<Monitor> monitors = Window::enumerateMonitors();

for (const auto& monitor : monitors) {
    std::cout << "Monitor: " << monitor.getName() << std::endl;
    std::cout << "Primary: " << (monitor.primary ? "Yes" : "No") << std::endl;
    
    // Get current video mode
    VideoMode current = monitor.getCurrentVideoMode();
    std::cout << "Current: " << current.width << "x" << current.height 
              << " @ " << current.refreshRate << "Hz" << std::endl;
    
    // Query all available modes
    auto modes = monitor.queryVideoModes();
    std::cout << "Available modes: " << modes.size() << std::endl;
}

// Set fullscreen on a specific monitor
if (!monitors.empty()) {
    window.setFullscreen(monitors[0]);
}

Build docs developers (and LLMs) love