Search code examples
c++user-interfacesdlresolution

screen resolution in c++


I made a simple game in C++ using SDL 1.2, and I used functions from wtypes.h to get display resolution, and then set game resolution at it's value. The problem is that when i compile it, exe file (my game's resolution) is dependent on resolution of computer it's compiled on. So when i copy exe file to another computer and it's run, the game resolution will be the same as my computer's resolution, not that computer's (unless they have same resolution). Is there a way get display resolution at runtime? I understand I can simply compile my cpp file at that computer, but that requires C:B/VS, dll files and linking dll files :/


Solution

  • The SDL_GetVideoInfo function returns a read-only pointer to a structure containing information about the video hardware. If it is called before SDL_SetVideoMode, member current_w and current_h of the returned structure will contain the pixel format of the best video mode.

    #include "SDL.h"
    
    SDL_Init( SDL_INIT_VIDEO );
    const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); 
    width = videoInfo->current_w;
    height = videoInfo->current_h;