SDL1 -> 使用自定义屏幕模式类构建 SDL2 分辨率列表
SDL1 -> SDL2 resolution list building with a custom screen mode class
我的引擎最近被转换为使用SDL2运行的输入和视频。但是,我很难获得解决方案模式列表构建正常工作。我确实研究了SDL2的迁移指南以及大量的研究链接 - 我不确定如何进行,以后进行了几次失败的尝试。
因此,对于初学者,我有一个称为i_video.cc的文件,该文件处理SDL2视频代码。99%的发动机在OpenGL中运行,因此SDL仅在那里初始化窗口并设置任何变量。
因此,这是将分辨率纳入我们的屏幕模式类的旧方法。作为参考,屏幕模式类是在r_modes.cc。
中定义的话虽如此,这是构建屏幕模式列表的旧的基于SDL1的代码,我无法在SDL2下运行。该代码从i_video.cc的第190行开始。作为参考,旧代码:
// -DS- 2005/06/27 Detect SDL Resolutions
const SDL_VideoInfo *info = SDL_GetVideoInfo();
SDL_Rect **modes = SDL_ListModes(info->vfmt,
SDL_OPENGL | SDL_DOUBLEBUF | SDL_FULLSCREEN);
if (modes && modes != (SDL_Rect **)-1)
{
for (; *modes; modes++)
{
scrmode_c test_mode;
test_mode.width = (*modes)->w;
test_mode.height = (*modes)->h;
test_mode.depth = info->vfmt->BitsPerPixel; // HMMMM ???
test_mode.full = true;
if ((test_mode.width & 15) != 0)
continue;
if (test_mode.depth == 15 || test_mode.depth == 16 ||
test_mode.depth == 24 || test_mode.depth == 32)
{
R_AddResolution(&test_mode);
}
}
}
// -ACB- 2000/03/16 Test for possible windowed resolutions
for (int full = 0; full <= 1; full++)
{
for (int depth = 16; depth <= 32; depth = depth + 16)
{
for (int i = 0; possible_modes[i].w != -1; i++)
{
scrmode_c mode;
mode.width = possible_modes[i].w;
mode.height = possible_modes[i].h;
mode.depth = depth;
mode.full = full;
int got_depth = SDL_VideoModeOK(mode.width, mode.height,
mode.depth, SDL_OPENGL | SDL_DOUBLEBUF |
(mode.full ? SDL_FULLSCREEN : 0));
if (R_DepthIsEquivalent(got_depth, mode.depth))
{
R_AddResolution(&mode);
}
}
}
}
它已注释,您可以在其上方看到设置SDL_CreateWindow的SDL2代码。该视频在游戏中很好,但是如果没有解决方案构建,我们将在程序加载之前先首先通过命令行参数而进行屏幕分辨率更改。我希望他们留下某种兼容性层,因为SDL2似乎在我一直在SDL1下处理的方式中有一条细微的学习曲线。
我知道listModes和videoinfo不再存在,并且我尝试用等效的SDL2函数(例如getDisPlayModes)替换它们,但是代码无法正常工作。我不确定我应该如何做到这一点,或者如果R_Modes.cc只需要完全重新制作,但是我需要做的就是获取视频模式列表以填充我的scrmode_c class(in r_modes.cc)。
当我尝试用sdl2替换所有内容时,我会从sdl_rect*到sdl_rect **的无效铸造,所以也许我只是做错了这一切。我花了几个月的时间试图使它正常工作,而且它不想。我不太在意设置每个像素,因为现代机器现在可以默认为24,我们不需要任何理由将其设置为16或8(如今,每个人都有一张可以使用的OpenGL卡高于16位BPP);)
任何建议,帮助...此时的任何事情都将不胜感激=)
谢谢!-coraline
使用sdl_getnumdisplaymodes和sdl_getDisPlayMode的组合,然后将它们推回SDL_DISPLAYMODE的向量。
。std::vector<SDL_DisplayMode> mResolutions;
int display_count = SDL_GetNumVideoDisplays();
SDL_Log("Number of displays: %i", display_count);
for (int display_index = 0; display_index <= display_count; display_index++)
{
SDL_Log("Display %i:", display_index);
int modes_count = SDL_GetNumDisplayModes(display_index);
for (int mode_index = 0; mode_index <= modes_count; mode_index++)
{
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
if (SDL_GetDisplayMode(display_index, mode_index, &mode) == 0)
{
SDL_Log(" %i bppt%i x %i @ %iHz",
SDL_BITSPERPIXEL(mode.format), mode.w, mode.h, mode.refresh_rate);
mResolutions.push_back(mode);
}
}
}
- 在 eclipse 中以发布模式构建后没有可执行文件
- 使用 RxCpp 构建观察者/可观察模式
- Visual Studio在发布模式下构建,但用户收到消息说他们需要调试文件
- 混合模式程序集是针对版本 'v2.0.50727' 构建的 ...本机C++/Visual C++/C# 项目错误
- MSVC 编译器在调试模式下构建 Qt 5.10 时崩溃
- 在发布模式下使用 VS2017 在C++发布模式下构建的应用不会在未经处理的异常时中断
- 在调试模式下构建 OpenCV 并进行了优化
- 构建器模式 - 配置文件读数
- SDL1 -> 使用自定义屏幕模式类构建 SDL2 分辨率列表
- 在Windows NTS模式下构建PHP扩展
- 如何在没有Python调试库的调试模式下使用Cmake/VisionStudio构建OpenCV
- C++模板问题,将构建器模式拉到配置中
- 使用 biicode cmake 在调试模式下构建 C++
- 如果我在DFS方法中生成频繁模式,如何构建DFS树
- 需要帮助构建正则表达式模式
- 有没有比这更有效的方法来构建/模式C++
- 发布模式下的Dartium构建错误
- 使用发布模式构建c++,库处于调试模式
- 如何处理由于项目中涉及的库的不同构建标志而出现的当前堆错误(在调试模式下)
- 代码:块调试模式:我的代码崩溃,如果构建和运行,但如果调试/继续