|
Size: 1851
Comment: Corrected includes.
|
Size: 1797
Comment: Changed example to be more compatible with C (was C++).
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 28: | Line 28: |
| #include <iostream> using namespace std; |
#include <stdio.h> |
| Line 34: | Line 32: |
| SDL_Init(SDL_INIT_VIDEO); |
int i; |
| Line 39: | Line 37: |
| SDL_Init(SDL_INIT_VIDEO); |
|
| Line 40: | Line 40: |
| for(int i=0; i < SDL_GetNumVideoDisplays(); ++i){ | for(i = 0; i < SDL_GetNumVideoDisplays(); ++i){ |
| Line 43: | Line 43: |
| Line 46: | Line 46: |
| cout << "Could not get display mode for video display #" << i << ": " << SDL_GetError(); | printf("Could not get display mode for video display #%d: %s", i, SDL_GetError()); |
| Line 50: | Line 50: |
| cout << "Display #" << i << ": current display mode is " << current.w << 'x' << current.h << "px @ " << current.refresh_rate << "hz. \n"; | printf("Display #%d: current display mode is %dx%dpx @ %dhz. \n", i, current.w, current.h, current.refresh_rate); |
SDL_GetCurrentDisplayMode
Use this function to get information about the current display mode.
Contents
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, ¤t);
if(should_be_zero != 0)
// In case of error...
printf("Could not get display mode for video display #%d: %s", i, SDL_GetError());
else
// On success, print the current display mode.
printf("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
You can add useful comments here
