Skip to main content
Version: Next (dev)

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.

note

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​

ModeDisplay.ModeBehaviour
Fixed window0Framed, not resizable. Fitted into the monitor's work area.
Resizable window1Framed and resizable. Fitted into the monitor's work area.
Borderless2Covers the monitor at its desktop resolution. The recommended fullscreen mode.
Fullscreen3Exclusive 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+Enter themselves set Window.AltEnterToggle to 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:

UIScale
Game UI canvas, Scale with HeightViewport height / reference height x Accessibility.UiScale. No DPI factor: it already follows the resolution.
Game UI canvas, Constant SizeDPI scale x Accessibility.UiScale. The same physical size on a 100 % and a 200 % monitor.
Debug textApp.TextScale x DPI scale.
ImGuiApp.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​

  1. 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.
  2. For a windowed default, give the Resolution in physical pixels. It is shrunk to the monitor's work area if it does not fit.
  3. 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.
  4. If the game binds Alt+Enter itself, set Window.AltEnterToggle to false.

Configuration​

CVarDefaultDescription
Window.DpiAwaretrueGame 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.AltEnterToggletrueAlt+Enter toggles between windowed and borderless fullscreen.
App.TextScale1The size of debug text and ImGui, multiplied by the DPI scale.
SettingDescription
Display.ModeThe window mode, see Window modes.
Display.MonitorThe monitor index, -1 for the primary monitor. Stored with the monitor's stable ID.
Display.Width, Display.HeightThe client size in physical pixels (windowed), or the display mode (exclusive fullscreen).
Display.RefreshRateExclusive fullscreen only. 0 uses the desktop rate.
Accessibility.UiScaleThe 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​

APIDescription
plScreen::GetScreenDetailsFriendly name, device name, stable ID, work area, DPI scale and current refresh rate of each screen (plScreenDetails).
plScreen::EnumerateDisplayModesA screen's display modes.
plScreen::FindScreenAt, FindScreenById, FindPrimaryScreenLookups in an enumerated screen list.
plWindow::GetDpiScale, GetCurrentScreenThe window's display scale and monitor.
plWindow::SetWindowModeInPlaceA mode or monitor change without a new window. Fails for entering exclusive fullscreen.
plWindow::GetWindowEventsDpiChanged, MonitorChanged and ModeChanged events.
plWindowCreationDesc::FitIntoWorkAreaCentres or clamps a window rectangle into a work area, shrinking it if needed.

Platforms​

PlatformState
Windows desktopEverything on this page.
Linux, macOSSizes are GLFW screen coordinates and the DPI scale is 1. No in-place mode switching.
AndroidPhysical pixels from the native window. No window modes.
Web, UWPFixed size at creation. No DPI scale.

Troubleshooting​

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

See Also​