pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping

Home Page:https://pthom.github.io/hello_imgui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

text blurry when connected to a non-retina external monitor

wkjarosz opened this issue · comments

On macOS with a MacBook Pro, I just noticed the following behavior:

launch a hello imgui app on:

  1. macbook with no external monitor connected: HighDPI resolution is detected properly and fonts are crisp
  2. macbook with external monitor connected and set to a retina resolution: HighDPI resolution is detected properly and fonts are crisp
  3. macbook with external monitor connected and set to a non-retina resolution: HighDPI resolution is seemingly not detected properly and fonts are blurry when moving the window from the non-retina monitor to the main retina display.

I have confirmed this behavior in my own apps, and also the fontawesome example in hello imgui.

Is there a way to handle case 3 above properly?

You are experiencing a known quirk with ImGui: see this extract from the ImGui FAQ:

The reason DPI is not auto-magically solved in stock examples is that we don't yet have a satisfying solution for the "multi-dpi" problem (using the docking branch: when multiple viewport windows are over multiple monitors using different DPI scales). The current way to handle this on the application side is:
Create and maintain one font atlas per active DPI scale (e.g. by iterating platform_io.Monitors[] before NewFrame()).
Hook platform_io.OnChangedViewport() to detect when a Begin() call makes a Dear ImGui window change monitor (and therefore DPI).
In the hook: swap atlas, swap style with correctly sized one, and remap the current font from one atlas to the other (you may need to maintain a remapping table of your fonts at varying DPI scales).

HelloImGui tries hard to add many additional steps to handle DPI correctly on different platforms.
However, this is a very difficult a time consuming task, since different platforms, or different app settings handle DPI differently.

Moving a window between monitors having different DPIs is not handled at the moment, since this would require 1/ changing the font atlas whenever the windows switches to a different monitor, and 2/ adapt the window size to account for the DPI change (on windows).

However, under macOS we might be lucky, since the window physical size (in millimeter) will likely not change when moving from one Retina screen to a non retina screen.

Last week, I was confronted to this issue, which lead me to introduce some settings:

See dpi_aware.h

If you create a hello_imgui.ini file where you place

[DpiAwareParams]
dpiWindowSizeFactor=1
fontRenderingScale=0.5

(or if you set those values inside runnerParams.dpiAwareParams), you will disconnect HelloImGui automatic DPI detection.

In this case, fonts will be loaded at twice the size and scaled by 0.5 upon rendering, which will likely improve the situation. The fonts will use more texture memory (but it will be the same as when running directly on the retina screen, since in that case HelloImGui will apply fontRenderingScale=0.5 automatically).

Please keep me informed of the result

Thanks. I can confirm that setting those programmatically does indeed make the app use crisp fonts on the retina screen (though the fonts therefore look notably crunchy/jagged on the non-retina screen -- a compromise I'm willing to deal with for now).

Thanks,
I took a few minutes to build and look at the imgui branch of your hdrview project, it looks extremely nice!

Thanks!