c++ - 如何在 SDL 中获取屏幕尺寸

标签 c++ sdl-2

我正在尝试使用 SDL 和 C++ 编写程序。如何在 SDL 中获取屏幕的宽度和高度(以像素为单位)?我试图获取屏幕的宽度而不是窗口的宽度。 . . .

最佳答案

在 SDL2 中,使用 SDL_GetCurrentDisplayModeSDL_GetDesktopDisplayMode根据您的需要。使用示例:

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

在高 DPI 显示器上,这将返回虚拟分辨率,而不是物理分辨率。

来自 SDL2 维基:

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.

关于c++ - 如何在 SDL 中获取屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33393528/

相关文章:

c++ - 在剪辑中复制环境的构造函数?

c++ - 为什么类的析构函数被调用两次?

c++ - SDL_PollEvent 有时在屏幕重新连接后不捕获触摸事件

c++ - SDL2 渲染器给我带来了问题

c++ - SDL2 SDL_CreateRenderer 降级OpenGL 上下文,是否可以阻止?

ubuntu - SDL2 看不到操纵杆,但操作系统可以

c++ - 在函数之间来回传递 char*

c++ - 无法在从 C++ 类继承的结构上调用正确的构造函数

c++ - 如何只将新文本写入文本文件

c - 如何在 SDL_Renderer 内移动单个元素?