Wiki Page Content

Differences between revisions 17 and 18
Revision 17 as of 2012-05-27 02:52:06
Size: 1857
Editor: ChrisBush
Comment: Slightly improved code example
Revision 18 as of 2013-07-06 08:39:56
Size: 1851
Comment: Corrected includes.
Deletions are marked like this. Additions are marked like this.
Line 26: Line 26:
#include <SDL2/SDL.h>
#include "SDL.h"

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 <iostream>   

using namespace std;

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO); 
  
  // Declare display mode structure to be filled in.
  SDL_DisplayMode current;

  // Get current display mode of all displays.
  for(int i=0; i < SDL_GetNumVideoDisplays(); ++i){
  
    int should_be_zero = SDL_GetCurrentDisplayMode(i, &current);
    
    if(should_be_zero != 0)
      // In case of error...
      cout << "Could not get display mode for video display #" << i << ": " << SDL_GetError();
    
    else 
      // On success, print the current display mode.
      cout << "Display #" << i << ": current display mode is " << current.w << 'x' << current.h << "px @ " << current.refresh_rate << "hz. \n";

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

Remarks

You can add useful comments here


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