Windows & displaysSDL 3.2

SDL_GetWindowDisplayScale

The scale at which content in this window should be drawn, e.g. 2.0 on a Retina screen or at 200%.

Signature

float SDL_GetWindowDisplayScale(SDL_Window *window);

How it works

It combines two things: the pixel density (how many pixels per window unit) and the user's scaling setting (125%, 150%…). Multiply your text and interface sizes by it, and they look as big as the rest of the system.

Example: a 3840×2160-pixel window with scale 2.0 should look like a 1920×1080 window at scale 1.0.

Parameters

windowSDL_Window *

The window to ask about.

Return value

The scale, or 0.0f on failure.

Tips & pitfalls

  • It changes when the window moves to another monitor: SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED tells you.

Example

example.cpp
1float scale = SDL_GetWindowDisplayScale(window);
2TTF_SetFontSize(font, 16.0f * scale);
Official SDL wiki