如何在SDL中获取屏幕尺寸 [英] How to get screen size in SDL

查看:499
本文介绍了如何在SDL中获取屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. . . .

推荐答案

在SDL2中,使用 SDL_GetCurrentDisplayMode SDL_GetDesktopDisplayMode 取决于您的需求。用法示例:

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;

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

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

从SDL2 Wiki:

From the SDL2 wiki:


[ SDL_GetDesktopDisplayMode ()]和 SDL_GetCurrentDisplayMode (),当SDL在全屏模式下运行并更改分辨率时。在这种情况下,[ SDL_GetDesktopDisplayMode ()]将返回先前的本机显示模式,而不是当前的显示模式。

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.

这篇关于如何在SDL中获取屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆