Windows & displaysSDL 3.2

SDL_GetCurrentDisplayMode

Reads a monitor's current resolution and refresh rate.

Signature

const SDL_DisplayMode * SDL_GetCurrentDisplayMode(SDL_DisplayID displayID);

How it works

The SDL_DisplayMode has w and h (size), pixel_density (pixels per unit), refresh_rate (a float in Hz, e.g. 59.94f; 0 if unknown) and format.

The refresh rate tells you the frame budget: at 60 Hz each frame has 1000 / 60 ≈ 16.7 ms.

Parameters

displayIDSDL_DisplayID

The monitor, from SDL_GetDisplayForWindow or SDL_GetPrimaryDisplay.

Return value

A pointer owned by SDL (do not free), or NULL on failure.

Example

example.cpp
1const SDL_DisplayMode* mode = SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(window));
2if (mode) SDL_Log("%dx%d @ %.2f Hz", mode->w, mode->h, mode->refresh_rate);
Official SDL wiki