Resolution issues when in Fullscreen

I’m writing an app/game in SDL2/C++ in which the user can change the resolution as well as toggle fullscreen. For debug purposes, I’m writing text to the screen which displays the current resolution, retrieving the X/Y with SDL_GetWindowSize()

The resolutions I currently have enabled as options are:
320x240 (4:3)
640x480 (4:3)
960x720 (4:3)
1152x720 (16:10)
1280x720 (16:9)

To change resolutions, I’m using SDL_SetWindowSize(myWindow, x, y);
Changing resolutions is working as expected when in windowed mode. When I change res, the debug text displaying the resolution matches with the resolution the user chose. The problems begin with Fullscreen mode.

To toggle Fullscreen, I’m using SDL_SetWindowFullscreen(myWindow, 1);

This works with caveats, if I’m in 320x240 and I fullscreen, it works, but the debug resolution text displays 640x480, well, I assume that’s simply because 320x240 is too small of a res for the monitor to fullscreen, so maybe SDL adapts and picks the next-smallest supported res, being 640x480, so that’s fine if that’s what’s happening. But from this fullscreened state, if I opt to change resolution again, nothing seems to change or update. The window size debug text still shows “640, 480” and that’s even if I choose different resolutions, while already fullscreened, that is.

Oddly, if I back out back to windowed mode, and then firstly change my resolution, for example to 960x720, and then go back into fullscreen, now the window size debug text updates, but even stranger, the dimensions don’t match up: “1024, 768” is now displayed in debug text. I tested all resolutions this way, and these are the results:

320x240,  then choose fullscreen = 640, 480
640x480,  then choose fullscreen = 640, 480
960x720,  then choose fullscreen = 1024, 768
1152x720, then choose fullscreen = 1280, 720
1280x720, then choose fullscreen = 1280, 720

To recap the two issues, the first is that changing res while fullscreened seems to not update anything. The second problem is unwanted/mismatched fullscreened window sizes on some, but not all, of my res choices. Thank you for any advice!

As far as I understand, when you set SDL fullscreen, it must match one of the resolutions provided by the hardware, so it goes into the closest matching resolution. It then has a something called logicalScaling that tries to scale the image to better fit the expected offset (and/or it is centering your game on the now mismatched screen).

When you switch to SDL3, there’s a helpful function.
I think your best option is to query the device to get the available resolutions, and set your game to match those on the fly. Here’s the link to the function I’m thinking of;

Set the displayID to zero to query the main display, and you can pretty much ignore the second variable. The function will return a list of displayModes that you can then iterate through and check for the available fullscreen resolutions on your device.

Otherwise you might have to figure out the available displayModes using SDL2/SDL_GetClosestDisplayMode - SDL Wiki

My thinking is that since you already scale your game to fit a list of resolutions that you created, it should not be too hard to now set those to the actual available resolutions instead. (On the fly).

Another thing to look into is setting the logical scaling, though I don’t have experience in that to know how that might work.