我正在试着用SDL和C++做一个程序。如何在SDL中获取屏幕的宽度和高度?我正在尝试获取屏幕的宽度,而不是窗口的宽度。。。。
发布于 2015-10-28 22:25:54
在SDL2中,根据需要使用SDL_GetCurrentDisplayMode或SDL_GetDesktopDisplayMode。使用示例:
SDL_DisplayMode DM;
SDL_GetCurrentDisplayMode(0, &DM);
auto Width = DM.w;
auto Height = DM.h;在高DPI显示上,这将返回虚拟分辨率,而不是物理分辨率。
从SDL2维基:
当SDL全屏运行并更改分辨率时,[SDL_GetDesktopDisplayMode()]和SDL_GetCurrentDisplayMode()之间存在差异。在这种情况下,[SDL_GetDesktopDisplayMode()]将返回以前的本机显示模式,而不是当前的显示模式。
发布于 2015-10-29 18:46:52
On Fullscreen:使用SDL_GetRendererOutputSize可以非常容易地完成
你只需要像这样传入一个你的SDL_Renderer*:
int w, h;
SDL_GetRendererOutputSize(renderer, &w, &h);空渲染器(SDL_Renderer*渲染器,int* w,int* h)
渲染器a渲染上下文
w用渲染器的宽度填充的指针
h用渲染器的高度填充的指针
非全屏上的:
使用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失败的时候你会讨厌你的生活的!
https://stackoverflow.com/questions/33393528
复制相似问题