Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL Backend: Supporting logical size in renderer #8339

Open
dbarkar opened this issue Jan 21, 2025 · 0 comments
Open

SDL Backend: Supporting logical size in renderer #8339

dbarkar opened this issue Jan 21, 2025 · 0 comments

Comments

@dbarkar
Copy link

dbarkar commented Jan 21, 2025

Version/Branch of Dear ImGui:

Version 1.91.6, Branch: XXX master

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_sdlrenderer2.cpp + imgui_impl_sdl3.cpp + imgui_impl_sdlrenderer3.cpp

Compiler, OS:

Windows 11 + MSVC2022

Full config/build information:

Dear ImGui 1.91.6 (19160)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1941
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl2
io.BackendRendererName: imgui_impl_sdlrenderer2
io.ConfigFlags: 0x00000001
 NavEnableKeyboard
io.ConfigViewportsNoDecoration
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00000C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.DisplaySize: 1445.00,1083.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

Both SDL2 and SDL3 allow a fixed logical resolution for rendering, regardless of the actual output resolution. For more information, please see https://wiki.libsdl.org/SDL3/SDL_SetRenderLogicalPresentation.

Currently, if the renderer uses logcal coordinates, imgui behavior is broken:

  1. UI is rendered to logical resolution and then scaled to window coordinates. I believe it should use window coordinates regardless of logical resolution.
  2. Mouse coordinates are off

As a workaround, I reset logical resolution before calling imgui frame and set it back after. Also I use SDL_RenderLogicalToWindow to convert mouse coordinates before sending them to imgui backend.

Maybe it's worth adding as a part of the library? Current behavior doesn't look good...

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

@ocornut ocornut changed the title [SDL] Supporting logical size in renderer SDL Backend: Supporting logical size in renderer Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants