Is it possible to completely stretch out a texture render (no aspect ratio correction) in window-fullscreen?

I want to do one simple thing that just seems to be impossible with SDL2…

I have a texture of 632x400 (yes, weird resolution) that is basically my framebuffer, and I want to stretch this out to fill the entire screen (in windowed-fullscreen mode), knowing that the aspect ratio will be off.

I can’t use SDL_RenderSetLogicalSize() as it tries to maintain the aspect ratio. So, what should I do?

I don’t think I understand what the problem is. If you use SDL_RenderCopy() to blit your framebuffer to the screen, you have full control over the aspect ratio.

I don’t want a specific aspect ratio, I just want to stretch the texture out to fill the entire screen. No borders, no overscan.

If you don’t use SDL_RenderSetLogicalSize and simply pass null as the fourth (last) argument to SDL_RenderCopy then it will cover the whole screen.

My program can run in these modes:

  1. A window with integer upscaling (default)
  2. Centered fullscreen (windowed)
  3. Stretched fullscreen (windowed)

This means a call to SDL_RenderSetLogicalSize was needed earlier on. How do I “undo” it when entering mode 3? I always pass NULL as the last argument of SDL_RenderCopy.

Just pass 0 for w and h.

SDL_RenderSetLogicalSize(renderer, 0, 0);

If you’re already using SDL_RenderCopy(), why do you need to call SDL_RenderSetLogicalSize()? Do all your scaling, aspect ratio etc. changes (to achieve modes 1, 2 & 3) by altering the parameters to SDL_RenderCopy() and don’t change the logical size.

This also ensures that only one scaling process will be used, rather than cascading two (one in SDL_RenderCopy and another as a result of SDL_RenderSetLogicalSize) with a potential unnecessary loss of quality.

I see, so I did it the wrong way all along. I rewrote the code to not use SDL_RenderSetLogicalSize at all, and in mode 2 I pass a custom rect to SDL_RenderCopy. Had to use SDL_GL_GetDrawableSize to get the hi-DPI scale factor on Macs with Retina, or else the image wouldn’t be the expected size.


Sadly, SDL_RenderSetLogicalSize is completely broken in SDL2.

It should have done exactly what you want. It did, when I first wrote the API and submitted it to the SDL project. But someone inside the project didn’t understand how it was supposed to work and hijacked it, changing its functionality severely in order to support a completely different, highly specific use case.

I unfortunately didn’t notice the change until after it had already been published, and no matter how strongly I pled my case that this is not how it was supposed to work, and that it would cause issues for other developers down the road, they refused to fix it, claiming that it was already in use by some existing project and we wouldn’t want to break their work. (Remember the old story about the guy who wrote make discovering that it was unusable garbage but not wanting to fix it because it had 6 users already? …yeah. That spirit is unfortunately still alive and well today.)

Sam said it would be possible to fix it in the next version, so let’s hope we finally get a working Logical Size implementation in SDL3.

1 Like

I think what you want is SDL_LOGICAL_PRESENTATION_STRETCH in SDL3. Mason, did we miss anything there?

Looking at the code briefly, it looks like that’s right. I’ll have to test it to be certain.