# How to handle different resolutions in SDL2?

What is the easiest way to set different resolutions with SDL2?

I was trying to use the SDL_RenderSetScale() function first, but for some reason it alters the physics of the game (jumps are higher or smaller for example). My other guess was to use SDL_RenderSetLogicalSize(), since it was mentioned in another similar question here, but I'm not quite sure how it is supposed to work.

What I would simply like to do:

Let's say I have the game world seen in 320x240. Then no matter the resolution of the window, what we see in 320x240 is simply "scaled up". So for example: what is supposed to be 1 pixel in the "original view", becomes 4 pixel in 640x480 and so on, but all the logic still happens in 320x240. So when I move something by 1 pixel, it will move seemingly 4 pixels in 640x480, but only 1 logically.

Yes, in the situation you describe, you want to use SDL_RenderSetLogicalSize().
The function takes in the width and height of the logical viewport, which in your case is the resolution you want to program your game logic in. You would call SDL_RenderSetLogicalSize(renderer, 320, 240);, and after that you don't need to worry about resolution scaling. SDL will scale the rendering for you automatically, and you get resolution independence.
Now, there are a couple of downsides to using SDL_RenderSetLogicalSize: It will letter box the viewport, meaning that in certain resolutions you will get black boxes either to the top and bottom or left and right of the window. I also had some issues with rounding errors when using SDL_RenderSetLogicalSize, which created ugly artifacts between tile borders. Those could however be fixed using SDL_RenderSetIntegerScale.
• As I see it could be the function I'm looking for, but I'm still not sure how to use it. I create my window at the bigger size, then call SDL_RenderSetLogicalSize() with the smaller size, and it indeed scales up everything, but in the game window, I only see the top left portion of the game. Maybe I call it at the wrong time? – Letokteren Jul 30 '16 at 10:01