2D rendererSDL 3.2

SDL_SetRenderLogicalPresentation

Lets you draw at a fixed size (e.g. 640×360) and have SDL scale it to whatever the window is.

Signature

bool SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode);

How it works

Pixel-art games are designed for one small resolution. With a logical size, all your drawing coordinates stay in that resolution and SDL scales the result to the window, adding black bars if the proportions differ.

INTEGER_SCALE only scales by whole numbers (2×, 3×…), so every game pixel becomes the same number of screen pixels and nothing looks uneven.

Parameters

rendererSDL_Renderer *

The renderer.

wint

Logical width you draw in.

hint

Logical height you draw in.

modeSDL_RendererLogicalPresentation

How to fit the logical size into the window.

Common values

SDL_LOGICAL_PRESENTATION_LETTERBOX
Keep proportions, black bars on the sides that do not fit.
SDL_LOGICAL_PRESENTATION_INTEGER_SCALE
Whole-number scale only, centered. Best for pixel art.
SDL_LOGICAL_PRESENTATION_STRETCH
Fill the window, distorting proportions.
SDL_LOGICAL_PRESENTATION_OVERSCAN
Fill the window, cutting off the parts that overflow.
SDL_LOGICAL_PRESENTATION_DISABLED
Turn it off: draw in real pixels again.

Return value

true on success, false on failure.

Tips & pitfalls

Example

example.cpp
1SDL_SetRenderLogicalPresentation(renderer, 640, 360,
2                                 SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
3// from now on, (0,0)-(640,360) covers the game area in any window size
Official SDL wiki