c++ - 如何在 SDL 中更改窗口的分辨率?一切都太大了

标签 c++ sdl-2

我正在使用 SDL 制作游戏并且监督了该决议。一切( Sprite )都太大了,我想知道我是否可以提高分辨率,使一切变小而不改变每个 Sprite 或修改表面的创建方式?这是我正在处理的内容:

my game (png)

最佳答案

自 SDL 2.0.0 起,您可以使用函数 SDL_RenderSetLogicalSize to set a device independent resolution for rendering .

通过这种方式,您可以使用所需的目标分辨率设置渲染器并绘制所有内容,就好像您正在使用该分辨率一样。

我引用官方documentation :

This is nice in that you can change the logical rendering size to achieve various effects, but the primary use is this: instead of trying to make the system work with your rendering size, we can now make your rendering size work with the system. On my 1920x1200 monitor, this app thinks it's talking to a 640x480 resolution now, but SDL is using the GPU to scale it up to use all those pixels. Note that 640x480 and 1920x1200 aren't the same aspect ratio: SDL takes care of that, too, scaling as much as possible and letterboxing the difference.

请注意,您可以控制 bunch of hints 的缩放方式。 ,例如 SDL_HINT_RENDER_SCALE_QUALITY

关于c++ - 如何在 SDL 中更改窗口的分辨率?一切都太大了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34520273/

相关文章:

c++ - 一维智能指针不适用于语法(*)++

C++ 语法 - 模板 <class ...Options>

c++ - 理解 openCV 代码片段

cygwin - 在cygwin中安装SDL

c++ - 如何在CMake中手动链接SDL2

c - 如何启用 SDL2 以允许所有 key_down 事件而不仅仅是退出事件?

c++ - 当我从 main 调用 ctor 时,为什么在范围结束之前调用 dtor? (实验性的)

c++ - 为什么这个 union 结构会导致内存泄漏?

c++ - 使用 SDL2 从 C++11 线程可移植地退出 readline

javascript - 使用 SDL2 + emscripten 时浏览器不加载本地镜像