Display Scaling, Monitors and Window Modes
Games built on plGameApplication (the Player included), the editor and the editor's engine process are per-monitor DPI aware on Windows. A game window is measured in physical pixels, its swapchain is always exactly the size of its client area, and Windows never stretches the image. Players can pick a monitor, a window mode, a resolution and, for exclusive fullscreen, a refresh rate on any connected monitor.
Game windows are sized in physical pixels. A 1280 x 720 window on a 150 % monitor now covers 1280 x 720 screen pixels, so it looks two thirds of the size it had in older builds, which let Windows stretch it. Windowed sizes saved by older builds are rescaled once (see Saved window sizes). Borderless fullscreen is not affected.
Window modes
| Mode | Display.Mode | Behaviour |
|---|---|---|
| Fixed window | 0 | Framed, not resizable. Fitted into the monitor's work area. |
| Resizable window | 1 | Framed and resizable. Fitted into the monitor's work area. |
| Borderless | 2 | Covers the monitor at its desktop resolution. The recommended fullscreen mode. |
| Fullscreen | 3 | Exclusive fullscreen: changes the monitor's display mode. Works on any monitor. |
Windows are centred in the target monitor's work area and shrunk to fit it if they are too large.
Switching between the two windowed modes and borderless, or moving to another monitor, keeps the window and swapchain. Entering exclusive fullscreen creates them again. Every display change from the settings menu waits for confirmation and reverts on its own, see Applying Settings.
- Alt+Enter switches between the window's windowed mode and borderless fullscreen on the monitor the window is on. From exclusive fullscreen it goes windowed. The game settings record the new mode, and it is saved the next time the player applies settings. Projects that bind
Alt+Enterthemselves setWindow.AltEnterToggleto false. - Alt+Tab from exclusive fullscreen: while another application is active, the game minimises and gives the monitor its desktop mode back. It sets its mode again when it is activated.
- A monitor is disconnected: the window moves to the primary monitor, and exclusive fullscreen becomes borderless there.
Monitors
Display.Monitor is an index into the connected monitors, and -1 means the primary monitor. The settings file also stores the monitor's stable ID, so the choice survives monitors being plugged in again in another order. If the saved monitor is not connected, the game opens on the primary monitor.
The built-in settings page shows each monitor as name, W x H, scale %, and lists the resolutions and refresh rates of the selected monitor.
Display scale changes
When a window moves to a monitor with another scale, or the Windows scale changes while the game runs, the window takes the size Windows suggests (the same apparent size), and the swapchain follows on the next frame. While you drag the window frame, the swapchain is resized once, when the drag ends.
Every time the swapchain is created or resized, the log gets a line such as Swapchain 1280x720, window client area 1280x720.
Saved window sizes
A windowed size saved by an older build is in 96 DPI units. When the settings file is read, such a size is multiplied once by the DPI scale of its monitor, so the window keeps its apparent size. The device block in GameSettings.ddl then carries Units "Physical" and is never scaled again. Fullscreen sizes are display modes and were always physical.
UI scale
Only UI that has a constant physical size takes the display's DPI scale:
| UI | Scale |
|---|---|
| Game UI canvas, Scale with Height | Viewport height / reference height x Accessibility.UiScale. No DPI factor: it already follows the resolution. |
| Game UI canvas, Constant Size | DPI scale x Accessibility.UiScale. The same physical size on a 100 % and a 200 % monitor. |
| Debug text | App.TextScale x DPI scale. |
| ImGui | App.TextScale x DPI scale. |
plGameApplication::GetMainWindowDpiScale() returns the DPI scale of the main window's monitor. In the editor's viewports it is the editor window's scale. The editor's own pixel ratio no longer overwrites the saved App.TextScale.
Setting up a project
- Choose the default mode in
RuntimeConfigs/Window.ddl(the Window section of the Build & Export dialog's Runtime tab). Borderless suits most games: it renders at the monitor's native resolution at any scale. - For a windowed default, give the Resolution in physical pixels. It is shrunk to the monitor's work area if it does not fit.
- Author HUD elements that should keep a physical size (cross-hairs, small icons) on Constant Size canvases, and everything laid out against a reference resolution on Scale with Height canvases.
- If the game binds
Alt+Enteritself, setWindow.AltEnterToggleto false.
Configuration
| CVar | Default | Description |
|---|---|---|
Window.DpiAware | true | Game windows are per-monitor DPI aware. Off: windows created afterwards are DPI unaware, sizes are in 96 DPI units and Windows stretches them on scaled monitors, as in older builds. |
Window.AltEnterToggle | true | Alt+Enter toggles between windowed and borderless fullscreen. |
App.TextScale | 1 | The size of debug text and ImGui, multiplied by the DPI scale. |
| Setting | Description |
|---|---|
Display.Mode | The window mode, see Window modes. |
Display.Monitor | The monitor index, -1 for the primary monitor. Stored with the monitor's stable ID. |
Display.Width, Display.Height | The client size in physical pixels (windowed), or the display mode (exclusive fullscreen). |
Display.RefreshRate | Exclusive fullscreen only. 0 uses the desktop rate. |
Accessibility.UiScale | The player's multiplier for game UI. |
The settings command bridge (plGameSettings::Execute) replies with DisplayModes, every mode of every monitor with Monitor set to its index (the primary monitor's modes appear again under -1), and with Monitors (Index, Name, Id, Width, Height, OffsetX, OffsetY, Scale, RefreshRate, Primary).
Engine API
| API | Description |
|---|---|
plScreen::GetScreenDetails | Friendly name, device name, stable ID, work area, DPI scale and current refresh rate of each screen (plScreenDetails). |
plScreen::EnumerateDisplayModes | A screen's display modes. |
plScreen::FindScreenAt, FindScreenById, FindPrimaryScreen | Lookups in an enumerated screen list. |
plWindow::GetDpiScale, GetCurrentScreen | The window's display scale and monitor. |
plWindow::SetWindowModeInPlace | A mode or monitor change without a new window. Fails for entering exclusive fullscreen. |
plWindow::GetWindowEvents | DpiChanged, MonitorChanged and ModeChanged events. |
plWindowCreationDesc::FitIntoWorkArea | Centres or clamps a window rectangle into a work area, shrinking it if needed. |
Platforms
| Platform | State |
|---|---|
| Windows desktop | Everything on this page. |
| Linux, macOS | Sizes are GLFW screen coordinates and the DPI scale is 1. No in-place mode switching. |
| Android | Physical pixels from the native window. No window modes. |
| Web, UWP | Fixed size at creation. No DPI scale. |
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| The game window is smaller than before on a high-DPI monitor. | Sizes are physical pixels now. Use borderless, or ask for a larger window. Saved sizes from older builds are scaled once. |
| The image is blurry on a scaled monitor. | Window.DpiAware is off, or a host application made the process DPI unaware before the engine started. |
The log reports a Swapchain ..., window client area ... (mismatch) line. | The swapchain could not follow a resize yet and retries the next frame. A lasting mismatch is a bug. |
| Exclusive fullscreen opens on the wrong monitor. | The saved monitor was disconnected or re-ordered. Pick it again in the settings. |
| UI looks twice as large after moving to a 200 % monitor. | Expected for Constant Size canvases and debug text. Scale with Height canvases do not change. |
| The frame rate dropped on a high-DPI monitor. | The game now renders every physical pixel, up to 2.25 times as many at 150 %. Use the upscaler or dynamic resolution quality settings. |