How to get screen size in SDL

前端 未结 2 1223
情深已故
情深已故 2021-01-02 15:00

I\'m trying to make a program using SDL and C++. How can I get screen\'s width and height in pixels in SDL?I\'m trying to get screen\'s width not the window\'s width.

2条回答
  •  情书的邮戳
    2021-01-02 15:24

    In SDL2, use SDL_GetCurrentDisplayMode or SDL_GetDesktopDisplayMode depending 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 the virtual resolution, not the physical resolution.

    From the SDL2 wiki:

    There's a difference between [SDL_GetDesktopDisplayMode()] and SDL_GetCurrentDisplayMode() when SDL runs fullscreen and has changed the resolution. In that case [SDL_GetDesktopDisplayMode()] will return the previous native display mode, and not the current display mode.

提交回复
热议问题