Wiki Page Content


Use this function to get information about a specific display mode.


int SDL_GetDisplayMode(int              displayIndex,
                       int              modeIndex,
                       SDL_DisplayMode* mode)

Function Parameters


the index of the display to query


the index of the display mode to query


an SDL_DisplayMode structure filled in with the mode at modeIndex

Return Value

Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.

Code Examples

    int display_count = 0, display_index = 0, mode_index = 0;
    SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };

    if ((display_count = SDL_GetNumVideoDisplays()) < 1) {
        SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count);
        return 1;

    if (SDL_GetDisplayMode(display_index, mode_index, &mode) != 0) {
        SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError());
        return 1;       
    SDL_Log("SDL_GetDisplayMode(0, 0, &mode):\t\t%i bpp\t%i x %i",
    SDL_BITSPERPIXEL(mode.format), mode.w, mode.h);


The display modes are sorted in this priority:

  • width -> largest to smallest

  • height -> largest to smallest

  • bits per pixel -> more colors to fewer colors

  • packed pixel layout -> largest to smallest

  • refresh rate -> highest to lowest

CategoryAPI, CategoryVideo

None: SDL_GetDisplayMode (last edited 2014-06-29 22:03:03 by dthree)

Please include your contact information if you'd like to receive a reply.