ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.21k stars 10.31k forks source link

UIScale by rendering to offscreen texture in SDL2? #6511

Open dacobi opened 1 year ago

dacobi commented 1 year ago

This isn't really an issue, but more of a question.

I've been wanting to implement UI scaling in my app for High DPI monitors and I thought the simplest approach would be to just render the entire program to an offscreen render texture and then scale that.

I've been looking at ScaleAllSizes/FontsGlobalScale/ScaleWindowsInViewport but can't get anything to work.

The problem seems to be that no matter what I do there's problems with ImGui and mouse cursor pos/window pos's/sizes, when the offscreen render texture has a different size than the window.

So my question is simply if this is at all possible? Or if I should just bite the bullet and scale everything manually.

I'm sorry if this is not the correct place to ask.

ocornut commented 1 year ago

There are dozens of same issue tagged with dpi. I don’t have time to answer again, I’ll work on adjusting examples and perhaps backends to make this easier. But there are many answers scattered around.

MacOS is a little trickier, and multi-monitor with varying dpI + multi-viewports trickier too.

dacobi commented 1 year ago

I know you've answered this many times, but I just wanted to ask if there's a correct way to set up UI scale where the mouse cursor pos is scaled?

Right now I have something working using SDL_RenderSetScale, but I had to apply this fix https://github.com/ocornut/imgui/issues/6065

And then manually scale the output from ImGui::GetMainViewport()->GetCenter();