Skip to main content

Creating a Window

Windows are the primary interface for interacting with the Atlas Engine. Every application starts by creating a window with specific configuration options.

Basic Window Creation

window.h:252-263
Window window({.title = "My Window",
               .width = 1600,
               .height = 1200,
               .renderScale = 5.0f,
               .mouseCaptured = true,
               .multisampling = false,
               .ssaoScale = 0.4f});
Render Scale: The renderScale parameter controls internal rendering resolution. Values below 1.0 render at lower resolution and upscale for better performance.

Window Configuration

The WindowConfiguration struct provides extensive customization options:

Configuration Options

PropertyTypeDefaultDescription
titlestd::string-Window title displayed in title bar
widthint-Window width in pixels
heightint-Window height in pixels
renderScalefloat0.75fInternal resolution scale factor
mouseCapturedbooltrueWhether to capture and hide cursor
posXintWINDOW_CENTEREDX position or WINDOW_CENTERED
posYintWINDOW_CENTEREDY position or WINDOW_CENTERED
multisamplingbooltrueEnable MSAA anti-aliasing
decorationsbooltrueShow title bar and borders
resizablebooltrueAllow user resizing
transparentboolfalseTransparent framebuffer
alwaysOnTopboolfalseKeep window above others
opacityfloat1.0fWindow opacity (0.0-1.0)
ssaoScalefloat0.5fSSAO quality scale

Example: Custom Configuration

WindowConfiguration config;
config.title = "My Game";
config.width = 1280;
config.height = 720;
config.renderScale = 0.8f;  // 80% internal resolution
config.multisampling = true;
config.decorations = true;
config.resizable = true;

Window window(config);

Setting Up the Window

After creating a window, you need to configure its scene and camera:
test/main.cpp:252-262
Window window({.title = "My Window",
               .width = 1600,
               .height = 1200,
               .renderScale = 5.0f,
               .mouseCaptured = true,
               .multisampling = false,
               .ssaoScale = 0.4f});
MainScene scene;
window.setScene(&scene);
window.run();

Window Loop

The run() method starts the main rendering loop:
// Start the window loop
window.run();
// This blocks until the window closes

Rendering Configuration

Deferred Rendering

test/main.cpp:247-248
window.usesDeferred = true;
window.enableSSR(true);

Clear Color

window.setClearColor(Color(0.1f, 0.1f, 0.15f, 1.0f));

Fullscreen & Display Modes

Enumerate Monitors

window.h:305
std::vector<Monitor> monitors = Window::enumerateMonitors();

for (const auto& monitor : monitors) {
    std::string name = monitor.getName();
    auto [width, height] = monitor.getPosition();
    VideoMode currentMode = monitor.getCurrentVideoMode();
    
    std::cout << "Monitor: " << name << " at (" 
              << width << ", " << height << ")" << std::endl;
    std::cout << "Current mode: " << currentMode.width << "x" 
              << currentMode.height << "@" 
              << currentMode.refreshRate << "Hz" << std::endl;
}

Enable Fullscreen

window.h:287-293
// Fullscreen on primary monitor
window.setFullscreen(true);

// Fullscreen on specific monitor
std::vector<Monitor> monitors = Window::enumerateMonitors();
if (!monitors.empty()) {
    window.setFullscreen(monitors[1]); // Second monitor
}

// Return to windowed mode
WindowConfiguration windowedConfig;
windowedConfig.width = 1280;
windowedConfig.height = 720;
window.setWindowed(windowedConfig);

Input Handling

The Window class provides input query methods:

Keyboard Input

window.h:372-379
if (window.isKeyPressed(Key::W)) {
    // Move forward while key is held
}

if (window.isKeyClicked(Key::Space)) {
    // Jump once when space is pressed
}

Mouse Control

window.h:385-397
// Release mouse cursor
window.releaseMouse();

// Capture mouse for camera control
window.captureMouse();

// Get cursor position
auto [x, y] = window.getCursorPosition();

Scene Input Handling

test/main.cpp:155-169
class MainScene : public Scene {
    void update(Window &window) override {
        camera.update(window);
        
        if (window.isKeyPressed(Key::Escape)) {
            window.releaseMouse();
        }
    }
    
    void onMouseMove(Window &window, Movement2d movement) override {
        camera.updateLook(window, movement);
    }
};

Time & Frame Information

window.h:364-459
// Get time since window creation
float time = window.getTime();

// Get delta time between frames
float dt = window.getDeltaTime();

// Get frames per second
float fps = window.getFramesPerSecond();

Render Targets

test/main.cpp:241-243
RenderTarget frameBuffer = RenderTarget(window, RenderTargetType::Scene);
window.addRenderTarget(&frameBuffer);
frameBuffer.display(window);

Adding Objects to Window

window.h:314-342
// Add regular 3D object
window.addObject(&cube);

// Add with higher rendering priority
window.addPreferencedObject(&importantObject);

// Add to render first
window.addPreludeObject(&skybox);

// Add UI element (rendered after world geometry)
window.addUIObject(&fpsText);

// Add to late forward queue
window.addLateForwardObject(&particles);

// Remove object
window.removeObject(&cube);

Physics & Audio

window.h:466-476
// Set gravity
window.gravity = 9.81f;  // Default is 9.81 m/s²

// Access physics world
if (window.physicsWorld) {
    // Physics operations
}

// Access audio engine
if (window.audioEngine) {
    // Audio operations
}

Debug Mode

window.h:441-446
// Enable debug rendering
window.activateDebug();

// Disable debug rendering
window.deactivateDebug();

Static Access

The main window can be accessed globally:
window.h:404
if (Window::mainWindow) {
    // Access from anywhere
    float fps = Window::mainWindow->getFramesPerSecond();
}

Advanced Configuration

Rendering Backend Access

window.h:504
std::shared_ptr<opal::Device> device = window.getDevice();

Viewport Control

window.viewportX = 0;
window.viewportY = 0;
window.viewportWidth = 1920;
window.viewportHeight = 1080;

Pipeline State

window.h:521-533
window.useDepth = true;
window.useBlending = true;
window.writeDepth = true;
window.cullMode = opal::CullMode::Back;
window.depthCompareOp = opal::CompareOp::Less;
window.frontFace = opal::FrontFace::CounterClockwise;

Example: Complete Window Setup

int main() {
    // Create window with configuration
    Window window({.title = "My Game",
                   .width = 1920,
                   .height = 1080,
                   .renderScale = 0.75f,
                   .mouseCaptured = true,
                   .multisampling = true,
                   .ssaoScale = 0.5f});
    
    // Configure rendering
    window.usesDeferred = true;
    window.enableSSR(true);
    window.setClearColor(Color(0.1f, 0.1f, 0.15f, 1.0f));
    
    // Set up scene
    MainScene scene;
    window.setScene(&scene);
    
    // Run main loop
    window.run();
    
    return 0;
}

Next Steps

Scene Management

Learn how to create and manage scenes

Objects & Components

Work with game objects and components

Build docs developers (and LLMs) love