How to get screen size in SDL

I am trying to create a program using SDL and C ++. How to get screen width and height in pixels in SDL? I am trying to get the width of the screen, not the width of the window.,.

+4
source share
2 answers

In SDL2, use SDL_GetCurrentDisplayModeor SDL_GetDesktopDisplayModedepending on your needs. Usage example:

SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
auto Width = DM.w;
auto Height = DM.h;

On high DPI displays, this will return virtual resolution, not physical resolution.

From the wiki of the SDL2 file:

[SDL_GetDesktopDisplayMode()] SDL_GetCurrentDisplayMode(), SDL . [SDL_GetDesktopDisplayMode()] , .

+8

: , SDL_GetRendererOutputSize

SDL_Renderer* :

int w, h;

SDL_GetRendererOutputSize(renderer, &w, &h);

void SDL_GetRendererOutputSize (SDL_Renderer * renderer,                        int * w,                        int * h)

,

,

Fullscreen:

SDL_GetDesktopDisplayMode()

SDL_DisplayMode dm;

if (SDL_GetDesktopDisplayMode(0, &dm) != 0)
{
     SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
     return 1;
}

int w, h;
w = dm.w;
h = dm.h;

! , SDL_GetDesktopDisplayMode !

+2

Source: https://habr.com/ru/post/1613503/


All Articles