Get information about the current display mode.
const SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID);
displayID | the instance ID of the display to query |
Returns a pointer to the desktop display mode or NULL on error; call SDL_GetError() for more information.
There's a difference between this function and SDL_GetDesktopDisplayMode() when SDL runs fullscreen and has changed the resolution. In that case this function will return the current display mode, and not the previous native display mode.
This function is available since SDL 3.0.0.
// Using SDL2's SDL_GetCurrentDisplayMode()
#include "SDL.h"
int main(int argc, char* argv[])
{int i;
// Declare display mode structure to be filled in.
SDL_DisplayMode current;
SDL_Init(SDL_INIT_VIDEO);
// Get current display mode of all displays.
for(i = 0; i < SDL_GetNumVideoDisplays(); ++i){
int should_be_zero = SDL_GetCurrentDisplayMode(i, ¤t);
if(should_be_zero != 0)
// In case of error...
"Could not get display mode for video display #%d: %s", i, SDL_GetError());
SDL_Log(
else
// On success, print the current display mode.
"Display #%d: current display mode is %dx%dpx @ %dhz.", i, current.w, current.h, current.refresh_rate);
SDL_Log(
}
// Clean up and exit the program.
SDL_Quit();return 0;
}