Application framerate drops significantly in fullscreen

Hello! I’ve recently started to learn SDL2 (using windows 7) and it’s been going great so far, however I’ve encountered an issue which I can’t seem to be able to fix.

Basically my application is a very simple tile drawing system (for now). There’s a tileset and tiles are drawn onto the screen from a map data. This works great with a solid 60 fps all the time. I want to now implement a fullscreen system, but using SDL_WINDOW_FULLSCREEN doesn’t cut it since it streches the pixel art. I want to maintain the aspect ratio of the original. I’ve already established a proper scale up and down system which allows the window to be resized with the pixel art resizing as well and this works great in windowed mode.

The problem is that as soon as I make my application go fullscreen using SDL_WINDOW_FULLSCREEN_DESKTOP the framerate drops significantly. I tried to see what could be going wrong, but I don’t really see any problems in my code or at least I can’t really spot them. The same does not happen with SDL_WINDOW_FULLSCREEN as that runs smooth without issues.

Instead of posting the full code here’s a brief rundown of what happens

pre loop

  • SDL, SDL_Image, SDL_TTF and SDL_Mixer are initialized
  • window (SDL_Window) is created
  • text variables are initialized (for debug display)
  • room data is loaded
  • tileset image is loaded

main program loop

  • handle SDL events
  • react to inputs (resizing and switching fullscreen happens here)
  • update debug text
  • render room
  • render debug text
  • delay the loop to achieve 60 fps

To activate fullscreen I use the following

fullscreen = true;
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
fullscreen_x = (display_mode.w - sc_w) / 2;
fullscreen_y = (display_mode.h - sc_h) / 2;

fullscreen is just a bool that stores the state of the program, window is the main SDL_Window, fullscreen_x and fullscreen_y are used as offsets for drawing the map in the center of the screen and display_mode is an SDL_DisplayMode variable for the monitor size.

sc_w and sc_h are the width and height of the screen.

I thought that maybe it’s the map being drawn that causes the lag, but even if I completely remove the map from the program and only leave the debug info the fps drops. I’m regulating fps using a timer that counts CPU ticks elapsed in each loop and delays each loop to adjust to 60 fps.

I also had a black border being drawn to hide the things that are “off screen”, but they don’t seem to affect the framerate. I currently have them removed.

I am using SDL_RenderSetScale to upscale the tileset, but that doesn’t seem to be it either since the lag is still there when this is removed.

So I then tried to create an application which only has 2 things, the window and an fps counter / limiter and then letting it enter fullscreen. Guess what… it still slows down to about 30 fps.

Then I tried removing everything so that nothing is being rendered and only fps is being reported to the console which yielded the following

60
59
59
59
59
enter fullscreen
41
33
33
33
33
33
leave fullscreen
43
59
59

59 is close enough to 60 to be good, but why does it lower to 33?

I’m at a loss here… Has anyone had similiar issues with SDL_WINDOW_FULLSCREEN_DESKTOP or am I doing something wrong?

EDIT : Forgot to mention I’m programming in c++

Hey!..
When I use SDL_WINDOW_FULLSCREEN_DESKTOP it works very well for me actually…
I use SDL_RenderSetLogicalSize() When I create the renderer so that it makes logic easier to manage if I scale things up…
Also, when I create the game’s window I don’t use fixed dimensions, I instead get the current display’s size with SDL_GetCurrentDisplayMode()
Beyond that I don’t do anything special at all…
I don’t think this will help you, but for me personally going fullscreen hasn’t been an issue

Thank you for your reply. After checking my code again and again I found something that could be the cause. When setting up my renderer I used to do this

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

As it turns out removing SDL_RENDERER_PRESENTVSYNC also removes my slowdown issues. I guess my monitors refresh rate changes when going fullscreen or something like that.

I’ll look into using SDL_RenderSetLogicalSize() since that could also help with being more efficient. I don’t think it matters whether you use fixed dimensions when creating the window or if you use SDL_GetCurrentDisplayMode() since that basically gives you fixed dimensions based on the resolution.

Now another slight issue arises. Without the vsync the fps goes well over 60. It reached around 65 at one point. I managed to fix this by setting the target fps to 57, but I’m worried that this might make the app less compatible with other systems. I’ll still look into it.

Weird… Maybe a hardware issue? But unlikely in my opinion.
I use SDL_RENDERER_PRESENTVSYNC the same way you do and my program runs just fine.
Sorry can’t help much, but I can’t think of a reason why that might be happening.