Issue Toggling Fullscreen on SDL2 on WinXP

I know it’s been a month, but I came across this thread while googling the same problem. Destroying and creating renderers every time I toggled felt rather wrong, and as bazz noted it can cause other unforeseen issues.

I’d actually highly recommend to anyone reading to stop using SDL_WINDOW_FULLSCREEN in favor of SDL2’s lovely new SDL_WINDOW_FULLSCREEN_DESKTOP. This lets you keep the same logical resolution without having to worry about whether the monitor supports it as a native resolution, and SDL will automagically handle any necessary scaling and/or letterboxing to keep the same aspect ratio. :smiley: Here’s what your function should look like bazz:

Code:
int SDL_ToggleFS(SDL_Window *win)
{
Uint32 flags = (SDL_GetWindowFlags(win) ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
if (SDL_SetWindowFullscreen(win, flags) < 0) // NOTE: this takes FLAGS as the second param, NOT true/false!
{
std::cout << "Toggling fullscreen mode failed: " << SDL_GetError() << std::endl;
return -1;
}
int w = 640, h = 480; // TODO: UPDATE ME
if ((flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0)
{
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, “linear”);
SDL_RenderSetLogicalSize(Renderer, w, h); // TODO: pass renderer as param maybe?
return 1;
}
SDL_SetWindowSize(win, w, h);
return 0;
}

You’ll also want to update your IsFullScreen method to check against the right flag of course. And for what it’s worth, I sorted this out for myself by reading the SDL2 Migration Guide (https://wiki.libsdl.org/MigrationGuide). Even if you’ve already read through it, another glance couldn’t hurt. 8)

Also thanks monkey0506

int SDL_ToggleFS(SDL_Window *win, int w, int h)
{
Uint32 flags = (SDL_GetWindowFlags(win) ^ SDL_WINDOW_FULLSCREEN_DESKTOP);
if (SDL_SetWindowFullscreen(win, flags) < 0) return -1; // NOTE: this takes FLAGS as the second param, NOT true/false!
SDL_SetWindowSize(win, w, h);
return 0;
}

Thanks for code bazz