SDL_GetClose...enDisplayMode(3)
β¨ SDL_GetClosestFullscreenDisplayMode β bestie edition β¨
okay so we're in the SDL3 FUNCTIONS section of the manual and today's main character is a lil function that finds you the display mode you actually want. let's get into it π
πΈ NAME πΈ
SDL_GetClosestFullscreenDisplayMode β get the closest match to the requested display mode.
like, you ask for a vibe, it finds the closest vibe that actually exists. no cap.
π¦ SYNOPSIS π¦
#include <SDL3/SDL_video.h>
bool SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, bool include_high_density_modes, SDL_DisplayMode *closest);
she takes six arguments and returns a bool. icon behaviour honestly.
π DESCRIPTION π
So here's the tea π: SDL goes and scans all the available display modes, and then fills in closest with the mode that best matches whatever you asked for β and hands it right back to you. obsessed.
Here's the little detail that matters: if the mode format and the refresh rate are set to 0, they just default to the desktop mode. easy. π
The scanning priority goes like this, and yes the order is important:
- size is first priority π
- format is second priority β¨
- and finally it checks the refresh rate π«
And if every single available mode is too small, then it returns false. π the disrespect, honestly.
π«Ά FUNCTION PARAMETERS π«Ά
displayIDβ the instance ID of the display you're querying. like, which screen are we talking about bestie.wβ the width in pixels of the display mode you want.hβ the height in pixels of the display mode you want.refresh_rateβ the refresh rate of the display mode you want, or0.0fif you just wanna roll with the desktop refresh rate.include_high_density_modesβ a boolean that decides whether high density modes get included in the search. highkey important on fancy screens πclosestβ a pointer that gets filled in with the closest display mode that's equal to or larger than the desired mode. she'll never give you something smaller, periodt.
π RETURN VALUE π
Returns true on success or false on failure. and if it fails? call SDL_GetError() for more info, she'll tell you what went wrong π«
π§ THREAD SAFETY π§
This function should only be called on the main thread. do not try her anywhere else, she's not about that life π
β AVAILABILITY β
This function is available since SDL 3.2.0. so if you're on something older... yeah. upgrade bestie π
π SEE ALSO π
and that's the whole page!! brought to you by Simple Directmedia Layer, version SDL 3.4.18 π stay slay, go get your closest display mode, and remember: size first, format second, refresh rate last. iykyk πΈβ¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms