Fullscreen - issues with DirectX and OpenGL

Hello guys

I have two rendering engines in my game. They are custom OpenGL and DirectX 9 (I do not use anything from SDL2 except for window management) and there are certain issues when I try to go fullscreen using function SDL_SetWindowFullscreen.

Following log is acquired when I try to switch to fullscreen from maximized window in OpenGL context:

SDL_WINDOWEVENT_SIZE_CHANGED: 640 480
SDL_WINDOWEVENT_SIZE_CHANGED: 1920 976
SDL_WINDOWEVENT_RESIZED: 1920 976
SDL_WINDOWEVENT_SIZE_CHANGED: 1920 1080
SDL_WINDOWEVENT_RESIZED: 1920 1080

Following log is acquired when I try to switch to fullscreen from not maximized window in OpenGL context:

SDL_WINDOWEVENT_SIZE_CHANGED: 640 480
SDL_WINDOWEVENT_SIZE_CHANGED: 640 480

Following is acquired when I try to switch to fullscreen from maximized window in DirectX 9 context:

SDL_WINDOWEVENT_SIZE_CHANGED: 640 480
SDL_WINDOWEVENT_SIZE_CHANGED: 1920 976
SDL_WINDOWEVENT_RESIZED: 1920 976
SDL_WINDOWEVENT_SIZE_CHANGED: 656 518
SDL_WINDOWEVENT_RESIZED: 656 518

Following is acquired when I try to switch to fullscreen from not maximized window in DirectX 9 context:

SDL_WINDOWEVENT_SIZE_CHANGED: 640 480
SDL_WINDOWEVENT_SIZE_CHANGED: 1920 1080
SDL_WINDOWEVENT_RESIZED: 1920 1080

The application starts with size of 640 x 480 since it’s the minimum size set by SDL_SetWindowMinimumSize and it’s size in general. After that it is resized to 1920 x 976 because the application requested maximization (SDL_MaximizeWindow). After that I hit “fullscreen” button which calls SDL_SetWindowFullscreen and somehow the received size is 656 x 518 instead of 1920 x 1080.

In order to properly go into a fullscreen mode with OpenGL context I need to have the window maximized. In order to properly go into a fullscreen mode with DirectX I need to have the window not maximized.

SDL2 is up to date - 2.0.4 from hg.

My bad - I did forget to mention that I was setting display mode within DirectX context when resetting parameters of the device:

Code:
SDL_DisplayMode displayMode;
displayMode.format = SDL_PIXELFORMAT_RGBX8888;
displayMode.w = 1920;
displayMode.h = 1080;
displayMode.refresh_rate = 0;
displayMode.driverdata = nullptr;
SDL_SetWindowDisplayMode(m_window, &displayMode);

That is why it properly went into a full screen on a non maximized window. Still, the behaviour is really strange and different on each context.

The question is how to properly go into a fullscreen mode (the highest available resolution) by using function SDL_SetWindowFullscreen in both contexts?

Have you tried this?

Code:
Uint32 flags = SDL_GetWindowFlags(MainWindow) ^ SDL_WINDOW_FULLSCREEN_DESKTOP;
SDL_SetWindowFullscreen(MainWindow, flags);------------------------
ePic Character Generator - endless character stream in your games using SDL 2.0:

Teaser video:

I did switch to SDL_WINDOW_FULLSCREEN_DESKTOP recently. However, even though I had SDL_WINDOW_FULLSCREEN_DESKTOP and size of current window was 640x480 the fullscreen instead of being 1920x1080 was 640x480. There are no events dispatched from SDL2 indicating a correct new resolution, however, sometimes it works (it depends whether the window is maximized, taking almost the whole screen, or it is a small window).

What I am currently doing is resizing the window to the size of the display and then going into a fullscreen - it seems to work most of the time, but with SDL_WINDOW_FULLSCREEN_DESKTOP I have yet another issue which did not happen on “true” fullscreen. The window seems to lose focus when going into a fullscreen at the first time from a small window. That is the window is visible at fullscreen, but my mouse events are focused at applications available at the background resulting in minimizing my window when I click anywhere on the screen, but when I go back the window has focus and everything works fine.

The issue is happening only with Direct3D context. It does not happen with OpenGL context created by the SDL2 itself.