Wiki Page Content

Differences between revisions 21 and 22
Revision 21 as of 2014-07-04 12:26:40
Size: 1985
Comment: printf -> SDL_Log in example.
Revision 22 as of 2015-04-26 18:43:27
Size: 1987
Comment: Added missing ().
Deletions are marked like this. Additions are marked like this.
Line 63: Line 63:
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. 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.

SDL_GetCurrentDisplayMode

Use this function to get information about the current display mode.

Syntax

int SDL_GetCurrentDisplayMode(int              displayIndex,
                              SDL_DisplayMode* mode)

Function Parameters

displayIndex

the index of the display to query

mode

an SDL_DisplayMode structure filled in with the current display mode

Return Value

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

Code Examples

// Using SDL2's SDL_GetCurrentDisplayMode()

#include "SDL.h"
#include <stdio.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, &current);

    if(should_be_zero != 0)
      // In case of error...
      SDL_Log("Could not get display mode for video display #%d: %s", i, SDL_GetError());

    else
      // On success, print the current display mode.
      SDL_Log("Display #%d: current display mode is %dx%dpx @ %dhz. \n", i, current.w, current.h, current.refresh_rate);

  }

  // Clean up and exit the program.
  SDL_Quit();
  return 0;

}

Remarks

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.


CategoryAPI, CategoryVideo

None: SDL_GetCurrentDisplayMode (last edited 2016-04-15 22:08:43 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit