Problem with switching between Full Screen to Window mode


#1

When I switch to Full Screen it works normal, but when I switch to the window mode with SDL_SetWindowDisplayMode, it displays the chosen texture in a window with the size of 1/10 of my monitor for sometime, and goes black.

After that, it switches back to Full Screen and display the texture normally, but I can’t receive any inputs in the window anymore.

Here how I’m handling this:

if ( mFullScreen )
{
SDL_DisplayMode DM;

		if (SDL_GetDisplayMode(0, 0, &DM) != 0)
			printf("Unable to get the DisplayMode! Error: %s\n", SDL_GetError());

		if (SDL_SetWindowDisplayMode(mWindow, &DM) != 0)
			printf("Unable to set the Window DisplayMode! Error: %s\n", SDL_GetError());

		mFullScreen = false;
	}
	else
	{
		SDL_SetWindowFullscreen(mWindow, SDL_WINDOW_FULLSCREEN);
		mFullScreen = true;
	}

But, when I handle it like this, it works:

	if ( mFullScreen )
	{
		SDL_SetWindowFullscreen(mWindow, 0);
		mFullScreen = false;
	}
	else
	{
		SDL_SetWindowFullscreen(mWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
		mFullScreen = true;
	}

Could anyone explain to me why this happens, or tell me what am I doing wrong?


#2

Looks like you’re setting the mode for fullscreen mode, but never leaving it. You’ll need to use: SDL_SetWindowFullscreen(mWindow, 0); to get out of fullscreen mode, and then use: SDL_SetWindowSize(SDL_Window* window, int w, int h) to set the size of the screen. The size, going black, and switching back to fullscreen mode might be due to the way SDL2 changes resolutions, but I’m not entirely sure right now.


#3

Seems like you was correctly, I tried it and it worked. But, I still wonder why with SDL_SetWindowDisplayMode it shows such strange behaviour.


#4

I ran into a strange issue with SDL 2.0.x on Ubuntu 16.04 and Intel graphics (standard driver that you get automatically) when trying to switch from window to “fullscreen desktop” - it would either fill the screen with a black window (with the mouse cursor working) or minimize the window in such a way that if you tried to restore it, it would instantly minimize again. Meanwhile, the program is waiting around in Xwindows calls for “something” to happen. Eventually I figured out that there appears to be a problem with XVidMode in this setup. When I use the SDL hint to disable the use of XVidMode, things work normally.