imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Blurry fonts in high DPI

Open ghost opened this issue 8 years ago • 8 comments
trafficstars

Hello. I tried use scaling in IMGui but seen that font too blurry. Also test window not scaling.

ghost avatar Mar 13 '17 21:03 ghost

You have to ask for double-sized fonts. Instead of asking for a size of 10, ask for 20, etc.

meshula avatar Mar 14 '17 05:03 meshula

Yeah I'd hoped that IO.FontGlobalScale would be applied when the font's texture is built, but it's applied afterwards and scales the texture. You can't rely on the default font since you'll need to pass in a size.

drewish avatar Mar 21 '17 06:03 drewish

A workaround for this is to add a font other than the default and setting OversampleH and OversampleH to something high, I use 3 for both. It looks pretty smooth in here.

Matheus28 avatar Jul 20 '17 06:07 Matheus28

This is still not resolved. I literally tried everything, default stb backend supports oversample which is in some cases even looking good, but not nice hinting in small font sizes. FreeType with oversampling, has nice hinting but oversampling does not work, as FreeType does not support oversampling and gives blurry fonts. How to make fonts look good on macOS with High DPI with FreeType? How to add oversampling to FreeType renderer?

slajerek avatar Dec 21 '21 18:12 slajerek

You don't need to change your font size, which will screw your layout. What you need is to increase resolution of generated font atlas. And that is what ImFontConfig::Density is for.

You can cherry pick patch to ImGui & FreeType atlas builder that add ImFontConfig::Density support from my feature/hidpi-support branch.

Note: Oversampling afaik is here to fight artifacts on small fonts rendered with stb_truetype. It it not suited to change atlas density.

MacBook iPad
MacBook@2 iPad@2

thedmd avatar Dec 22 '21 00:12 thedmd

@thedmd Do you have any plans to upstream the font density patch? (If not I might pick it up myself if it works well for me.)

whitequark avatar Jul 07 '24 23:07 whitequark

@whitequark Ability to control density was merged into ImGui about 8 months ago. I forgot about this thread, so I will take the opportunity now to mention it. :)

You can control density with RasterizationDensity.

https://github.com/ocornut/imgui/blob/1ec1f7a3de2ce96bee58b2825917707cc1b7c17c/imgui.h#L3005

thedmd avatar Jul 07 '24 23:07 thedmd

Thanks! This has sent me to a 7-hour-long rabbit hole of updating the Rust bindings...

whitequark avatar Jul 08 '24 08:07 whitequark

Seems the apple metal demo project text not supporting HDPI font scaling. The problem is the library is using the default font, for some reason DPI scaling is not working with the default font. If you look at the end of -(instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil function in the main.mm file, you can see commented code for loading custom fonts. uncomment one of these lines and give the correct path for the font. io.Fonts->AddFontFromFileTTF("/Users/abc/projects/imgui-docking/misc/fonts/DroidSans.ttf"); this should fix the font problem and would look gorgeous. (I couldn't get the relative path working, but the absolute path for the font worked, I think that is a my issue)

Image

jdchathuranga avatar Jun 16 '25 09:06 jdchathuranga