In my game, I’m supporting swapping between windowed, fullscreen, and “fullscreen window”. In code, this looks something like this:
switch( desiredWindowType )
{
case WindowType_Window:
SDL_SetWindowFullscreen(m_sdlWindow, 0);
SDL_SetWindowSize(m_sdlWindow, m_windowWidth, m_windowHeight);
break;
case WindowType_Fullscreen:
SDL_SetWindowFullscreen(m_sdlWindow, SDL_WINDOW_FULLSCREEN);
SDL_SetWindowDisplayMode(m_sdlWindow, &m_fullscreenDisplayMode);
break;
case WindowType_FullscreenWindow:
SDL_SetWindowFullscreen(m_sdlWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
{
SDL_DisplayMode desktopMode;
if ( SDL_GetDesktopDisplayMode(0, &desktopMode) == 0 )
SDL_SetWindowDisplayMode(m_sdlWindow, &desktopMode);
}
break;
}
The gotcha I’ve been running into is that sometimes I’ll get an apparently-spurious SDL_WINDOWEVENT_RESIZED
event after the mode change, reporting the resolution we had before the window resolution change. Which my code then dutifully obeys, and switches the resolution back.
Does the code above look correct to folks? (apart from the missing error testing, which I’ve removed here for conciseness)
The documentation doesn’t really specify whether I should be changing resolution/size before or after changing the fullscreen state of a window, so maybe I should be doing things in the opposite order; set size/display mode first, then fullscreen status afterward?
EDIT: For clarity; I’m currently testing under SDL 2.0.8, on Ubuntu, but I have seen the same or similar behaviour under SDL versions 2.0.4, 2.0.5, and 2.0.7, on both Windows and Linux. (I don’t have enough OSX testers to really definitively state whether it’s happening there, too. I’m assuming it’s a mistake on my side, rather than something in SDL)