SDL_RenderSetLogicalSize scaling behavior after renderer creation and high‑DPI hint interaction
0 reputation · 24 Apr 2021, 04:05 UTC
0 reputation · 24 Apr 2021, 04:05 UTC
When developing an SDL2 application that targets a fixed logical resolution, developers often call SDL_RenderSetLogicalSize after the renderer has been created to decouple drawing coordinates from the window pixel dimensions. The documentation states that the new logical size applies to subsequent drawing operations, but it is unclear whether the function also retroactively scales or reshapes content that has already been rendered to the render target. Additionally, on high‑DPI displays the logical size may be further modified by the system scaling factor unless SDL_HINT_VIDEO_HIGHDPI is disabled, and it is not specified how this interacts with the logical size set by the function.
Understanding these interactions is important for preserving visual fidelity and ensuring that UI elements appear at the intended size across different hardware configurations.
Does SDL_RenderSetLogicalSize affect pixels already present in the render target, or only future draw calls?
When SDL_HINT_VIDEO_HIGHDPI is set to 0, does the logical size remain exactly as specified, ignoring the display’s scale factor?
If both hints are active, what is the final scaling applied to rendered output?
SDL_RenderSetLogicalSize affects only subsequent draw calls. It does not retroactively rescale or reshape pixels already present in the render target.
When SDL_HINT_VIDEO_HIGHDPI is set to "0" before renderer creation, the logical size is applied exactly as specified, independent of the display's scaling factor.
If the high-DPI hint remains enabled (the default), the renderer maps the logical size to the physical backbuffer by multiplying by the display scale factor. The final output dimensions are logicalWidth * scaleFactor by logicalHeight * scaleFactor.
Confirmed by SDL documentation: changing the logical size alters the coordinate mapping for future rendering operations. Existing framebuffer content and previously rendered textures are not modified.
Likely explanation: the high-DPI hint controls whether SDL requests a high-DPI backbuffer from the platform window. When disabled, SDL uses a 1:1 pixel mapping. When enabled, SDL queries the display DPI and sizes the backbuffer accordingly, then applies the logical size as a viewport transform on top of that scaled backbuffer.
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI, "0") before SDL_CreateWindow and SDL_CreateRenderer.SDL_RenderSetLogicalSize(renderer, 800, 600).SDL_RenderReadPixels or SDL_GetRendererOutputSize to compare physical pixel dimensions."1" (or unset) and compare the output size.Because behavior can vary by backend and window flags, please confirm whether your window was created with SDL_WINDOW_ALLOW_HIGHDPI and which SDL version and video backend you are using. This determines whether the hint alone is sufficient or whether the window flag must also be cleared.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.