ocornut / imgui

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

How to implement HiDpi support with my custom renderer? #2746

Open Yatekii opened 5 years ago

Yatekii commented 5 years ago

Version/Branch of Dear ImGui:

Version: 1.71 Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui-rs > cimgui > imgui > cimgui > imgui-rs > wgpu > vulkan > GPU Compiler: rustc Operating System: Windows/Linux

Question:

First of all, I always knew about dear ImGui, but I always thought of it not being very cool looking and never gave it a try. Boy was I wrong. this thing is AWESOME! Since starting to use it last weekend I couldn't stop =D Thx so much for the lib!

I am using wgpu-rs and imgui-rs to render dear ImGui with wgpu in Rust. For this I took the previous work of some pal and added the missing pieces + API changes to make it work (the existing work was for waaay earlier releases of wgpu/imgui-rs which had a highly unstable API). This code is here: https://github.com/Yatekii/imgui-wgpu-rs/blob/master/src/lib.rs#L302-L409 . My question is: How do I properly implement rendering in HighDpi? Is there a guide for that? I have the renderer working including custom fonts and textures. just HiDpi does not work. On a normal 1080p display the results are great! I hope the code is understandable in Rust; this should be more of a question about how to do math and graphic-related setup for dear ImGui.

I hope I didn't miss anything in the FAQ, as I tried to find the answers there.

Best, Yatekii

P.S. A chat for ImGui would be awesome. I have seen previous issues for it and know your opinion, but opening issues or forum threads for simple questions or for quick exchange of help/descriptions of a problem is just not feasible :)

ocornut commented 5 years ago

There are various ways, the easier being to just load a font at double size and call ImGuiStyle::ScaleAllSizes() with that same factor. Since the majority of your size will be derived from font or style sizes it will work.

What we are missing is a standard float storage to query that scale for when we need to scale a constant not based on any font or style style, but it's better if you express them as factor of those. We don't have this official storage yet e.g. io.DpiScale ImGui::GetDpiScale() because the problem becomes widely more tricky with multi-viewports over multi-monitor with varying DPI scale.....

Also see #1786 and #1676

P.S. A chat for ImGui would be awesome. I have seen previous issues for it and know your opinion, but opening issues or forum threads for simple questions or for quick exchange of help/descriptions of a problem is just not feasible :)

Why it is not feasible? (Just you did it!)

There's something at https://gitter.im/ocornut/imgui and I just opened a Discord server yesterday (https://discord.gg/NgJ4SEP) as an attempt to communicate with some people I intend to work with, haven't used it yet. Maybe we can start promoting the Discord...

EDIT See #2748

(There's also a Discourse forum, the intent of it was to create something more lightweight to encourage people to post, but essentially it's just becoming a subpar version of Github Issues at the moment so I'm not sure it is worth keeping.)

imgui > cimgui > imgui-rs > wgpu > vulkan > GPU

Ouch! I hope by 2.0 we can start making some string-related change to make imgui more amenable to be used in Rust too..

Yatekii commented 5 years ago

Sorry for the long delay.

I think it's not a question of font scaling :/ Here is a correct screenshot on a 1080p display:

image

And here is a bad one:

image

I tried scaling the scissors which went horribad.

Somehow the canvas is just half the space. And the third window (the slim border visible in the image) is at the wrong place (dunno how that can happen because the other two are correct (the second one is moved; at launch its correct).

Well, imgui in rust awesome to use. couldn't wish for a better API tbh. Sure, native strings would be better, but that's about it. It's really not that bad :)

I like chats because it's waaaay easier to just quickly chat back and forth in realtime to solve a problem. On github or forums you have long brain breaks which let you drift from the problem and you have to rethink everything (sure, sometimes that's actually good).

ocornut commented 5 years ago

Hard to understand exactly what's going on I would suggest looking at the ImDrawList data via the Metrics window to understand the value you are getting and what is going wrong (viewport coordinates? scissors coordinates?). (Sorry DPI isn't yet an obviously-solved thing accross all platforms. :/)

Yatekii commented 5 years ago

Scissors coordinates look semi right as the scrissors for for example the scroll list are correct. They are scaled as well tho (otherwise it wouldn't match the scaled content, which it seems to do)

What is it with the viewport coordinates exactly? Btw, Iattached you the code sample where I do all the math in the first post. Maybe there is an obvious mistake. Especially the matrix I don't get what it is for tbh ^^