How to properly change window video mode and transfer it to other screens?

I’m tired of trying to find a working way to handle exclusive video mode. What should work because the documentation says so, doesn’t work. SDL has a notorious problem with supporting video modes on screens other than the primary one, and the resolution change suggested in the documentation doesn’t work properly, so you have to come up with strange solutions to avoid problems.

Question 1: How to activate video mode?

If the window is small with a border and I want to run exclusive video mode, what should I do? What I mean is how to run exclusive fullscreen on any display? Let’s assume that it is about the native resolution, i.e. display mode with index 0.

Question 2: How to change resolution when exclusive mode is already active?

Let’s assume that the window is currently displayed on a given display in native resolution (display mode with index 0). I want to change the display mode, e.g. to the one with index 1. Theoretically I should get the display mode using SDL_GetDisplayMode for the current display and then pass it to SDL_SetWindowDisplayMode. However, it doesn’t work properly, even for the primary display.

Ok, I finally dealt with it and implemented exclusive fullscreen support in my engine, for any display and any display mode it supports. Unfortunately, I couldn’t get the Direct3D backend to do this, but if I set OpenGL it works quite well. In case anyone is interested in this issue or if someone came here from a search engine, I wrote below how I did it.

The backend should be set to OpenGL by setting the SDL_RENDER_DRIVER hint to opengl.

Fullscreen dekstop can be set directly using the SDL_SetWindowFullscreen function and specifying the SDL_WINDOW_FULLSCREEN_DESKTOP flag. You don’t need to do anything extra and it should work on any display.

Fullscreen exclusive, regardless of which display it is to be launched on and with what display mode, should be launched in as follows:

The order in which the above functions are called is crucial. While exclusive fullscreen should work properly on any display and in any supported display mode, each time you change the display mode, it will redundantly disable fullscreen and restore it at the end, which causes additional screen flashing when changing modes (it takes two or three seconds at most). But slightly more screen flashing is better than completely glitched display.

OpenGL set as the backend does not support desktop fullscreen in the normal way. On the main screen, it runs a semi-exclusive fullscreen anyway, while on the secondary display this mode works as standard.

The second thing is that displaying the window in exclusive fullscreen on any screen and with a lower resolution than the native one causes a strange problem. When the mode setting is completed, simply move the mouse cursor to another screen (outside the window area), and when the cursor returns to the window area, SDL spontaneously sets the window size to native (and queues window resize events) and a large part of it does not fit in screen. This happens every time, for any display and any display mode. To avoid this, it is necessary to completely turn off fullscreen and turn it on again each time you change the display mode (I described it in the points above).

I also added this description in the issue regarding problems with exclusive fullscreen, because there are still problems with it. The issue with my posts can be found here: