我正在尝试使用 SDL 和 C++ 编写程序。如何在 SDL 中获取屏幕的宽度和高度(以像素为单位)?我试图获取屏幕的宽度而不是窗口的宽度。 . . .
最佳答案
在 SDL2 中,使用 SDL_GetCurrentDisplayMode
或 SDL_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/