SDL - Get native Screen Resolution

血红的双手。 提交于 2019-12-04 10:13:27

You have a problem with calling SDL Video Functions before actually initializing SDL.

SDL_Init( SDL_INIT_EVERYTHING )

has to be called before

SDL_GetVideoInfo(); 

In your case you call SDL_GetVideoInfo(); first

const SDL_VideoInfo* info = SDL_GetVideoInfo();   //<-- calls SDL_GetVideoInfo();   
screenWidth = info->current_w;
screenHeight = info->current_h;
Window(640, 480, "Flatgu game", "rsc/img/icon.bmp");    //<-- initializes SDL

So the solution is simple; make the call SDL_Init( SDL_INIT_EVERYTHING ) immediately at the start of your program, then you can call SDL_GetVideoInfo(); as much as you like. You will have to restructure your class Window slightly.

To get the best video mode call SDL_GetVideoInfo before setting up the video (before calling SDL_SetVideoMode).

But you still have to initialize the video subsystem before calling it (SDL_Init(SDL_INIT_VIDEO)).

jhoffman0x

I know this is old, but there's a big mistake in the code.

Window(640, 480, "Flatgu game", "rsc/img/icon.bmp");

creates a nameless instance of a Window, so the instance that calls it will still have uninitialized variables. It looks like you were trying to use delegating constructors, but in that case the call to the other constructor must be in the member initializer list. See this page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!