AFAIK SDL无法获得更新的分辨率(任何人如果我错了,请纠正我)。
你可以通过这种方式来做到这一点,就是使用你的操作系统的API。在你的情况下,你说你正在使用Windows。所以你可以继续使用Windows API来检索更新的分辨率信息。这显然不能移植到其他操作系统 - 所以你必须为你想要支持的每一个操作系统做到这一点。
我在答案的底部添加了一个小例子,它展示了如何在C++中检索主显示器的分辨率。如果你想更详细地处理多个显示器及其相对位置等,你应该看看this question。
#include "wtypes.h"
#include <SDL.h>
#include <iostream>
using namespace std;
void GetDesktopResolution(int& w, int& h)
{
RECT r;
GetWindowRect(GetDesktopWindow(), &r);
w = r.right;
h = r.bottom;
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow("SDL", 0, 0, 640, 480, SDL_WINDOW_RESIZABLE);
bool running = true;
while(running) {
SDL_Event game_event;
if(SDL_PollEvent(&game_event)) {
switch(game_event.type) {
case SDL_QUIT:
running = false;
break;
}
}
SDL_DisplayMode current;
SDL_GetCurrentDisplayMode(0, ¤t);
cout << "SDL" << current.w << "," << current.h << '\n';
int w, h;
GetDesktopResolution(w, h);
cout << "winapi" << w << "," << h << '\n';
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}