CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.6k stars 4.17k forks source link

Imgui rendered fonts do not look as crisp as in the other menus with the software renderer #73120

Open NetSysFire opened 6 months ago

NetSysFire commented 6 months ago

Describe the bug

image

Attach save file

n/a

Steps to reproduce

  1. Look at curses menus with lots of text. advanced inventory manager in this case.
  2. Press ? to look at keybindings.
  3. Brain immediately complains that the fonts look.. blurry? They definitely look off and not as crisp as the menu just before.

Expected behavior

Fonts look as crisp as in the ncurses menus.

Screenshots

No response

Versions and configuration

Additional context

No response

Qrox commented 6 months ago

Looks like the ImGUI window is using a different font. For example the r looks different from the non-ImGUI window. Also, if you look closely you can see that the ImGUI font has gray pixels which suggests that it fails to use the bitmap version of the vector font. Could you post your config/fonts.json?

NetSysFire commented 6 months ago

I do not remember changing anything of this, so it is probably the default.

{
  "typeface": [ "Terminus", "unifont" ],
  "map_typeface": [ "Terminus", "unifont" ],
  "overmap_typeface": [ "Terminus", "unifont" ]
}

Additionally, have all the font-specific options in options.json I grepped::

{ "info": "Highlight selected item's contents and parent container in inventory screen.  \"Symbol\" shows a highlighted caret and \"Highlight\" uses font highlighting.", "default": "Default: symbol - Values: symbol, highlight, disable", "name": "INVENTORY_HIGHLIGHT", "value": "symbol" },
{ "info": "If true, will display scrolling combat text with Unicode font.", "default": "Default: True", "name": "ANIMATION_SCT_USE_FONT", "value": "true" },
{ "info": "If true, vector fonts may look better.", "default": "Default: False", "name": "FONT_BLENDING", "value": "true" },
{ "info": "Set the font width.  Requires restart.", "default": "Default: 8 - Min: 6, Max: 100", "name": "FONT_WIDTH", "value": "8" },
{ "info": "Set the font height.  Requires restart.", "default": "Default: 16 - Min: 8, Max: 100", "name": "FONT_HEIGHT", "value": "16" },
{ "info": "Set the font size.  Requires restart.", "default": "Default: 16 - Min: 8, Max: 100", "name": "FONT_SIZE", "value": "16" },
{ "info": "Set the map font width.  Requires restart.", "default": "Default: 16 - Min: 6, Max: 100", "name": "MAP_FONT_WIDTH", "value": "16" },
{ "info": "Set the map font height.  Requires restart.", "default": "Default: 16 - Min: 8, Max: 100", "name": "MAP_FONT_HEIGHT", "value": "16" },
{ "info": "Set the map font size.  Requires restart.", "default": "Default: 16 - Min: 8, Max: 100", "name": "MAP_FONT_SIZE", "value": "16" },
{ "info": "Set the overmap font width.  Requires restart.", "default": "Default: 16 - Min: 6, Max: 100", "name": "OVERMAP_FONT_WIDTH", "value": "16" },
{ "info": "Set the overmap font height.  Requires restart.", "default": "Default: 16 - Min: 8, Max: 100", "name": "OVERMAP_FONT_HEIGHT", "value": "16" },
{ "info": "Set the overmap font size.  Requires restart.", "default": "Default: 16 - Min: 8, Max: 100", "name": "OVERMAP_FONT_SIZE", "value": "16" },
{ "info": "If true, use SDL ASCII line drawing routine instead of Unicode Line Drawing characters.  Use this option when your selected font doesn't contain necessary glyphs.", "default": "Default: True", "name": "USE_DRAW_ASCII_LINES_ROUTINE", "value": "true" },
Qrox commented 6 months ago

So, judging from the r character, the non-ImGUI window is using Terminus, whereas the ImGUI window is using unifont, so this is indeed related to #73061. The blurry characters is actually a separate issue related to unifont. The unifont we're using is a vector font without embedded bitmap font for specific font sizes, so it renders across pixel boundaries resulting in gray pixels.

I made a modified unifont file with embedded bitmap font for font size 16 in #66749 which can probably work around this problem. That PR has stalled, but you can try replacing data/font/unifont.ttf with the version in that PR and see if it fixes the blurry characters.

I'm not sure if we can fix it for all font sizes though. Previous I tried to shift the glyphs horizontally by a fraction of a pixel but that still resulted in blurry characters. Subpixel rendering might fix it but it was more complicated than I expected. Maybe we can let the user turn antialiasing on or off for individual fonts, which might fix it.

NetSysFire commented 6 months ago

That PR has stalled, but you can try replacing data/font/unifont.ttf with the version in that PR and see if it fixes the blurry characters.

I did but it does look even worse in this case than without the modified font. Worth a try though.

Qrox commented 6 months ago

I did but it does look even worse in this case than without the modified font.

Could you post a screenshot?

NetSysFire commented 6 months ago

Sure, with your custom font:

image

Without:

image

Qrox commented 6 months ago

Looks like it's still using the vector version of the font. Not sure if there's something wrong with the font or how ImGUI handles embedded bitmap font.

Qrox commented 6 months ago

image

Looks like it uses the bitmap glyphs for Chinese characters but uses the vector glyphs for English characters, and the color is also different. Intriguing. @katemonster33 Do you have any idea why this happens?

katemonster33 commented 6 months ago

image

Looks like it uses the bitmap glyphs for Chinese characters but uses the vector glyphs for English characters, and the color is also different. Intriguing. @katemonster33 Do you have any idea why this happens?

This happens because of #72579 , to get around ImGui's font rendering so that we can draw CJK characters without needing to cache all of them, I made ImGui call into CDDA's font rendering code to draw any character which doesn't exist in its cache.

We could have the same logic apply to all font drawing in ImGui, just have every character drawn by CDDA's code. This would have the added benefit of fixing the issue where ImGui does not respect the user's font choice. The only issue I could see would be the extra CPU usage, because ImGui screens tend to draw more frequently than the old screens. ImGui has this nice logic where it renders text in huge batches using SDL_RenderGeometry which makes it very efficient. But maybe the CPU hit won't be too bad.

katemonster33 commented 5 months ago

very weird. in windows the imgui UIs look fine.

Image

katemonster33 commented 5 months ago

Image I zoomed in on the 'X' button on the window. Linux on top, Windows on bottom. seems like transparency is off in linux? but why? so strange

Qrox commented 5 months ago

Is ImGUI using SDL for font rendering? If so you might want to check what blending mode and font hinting is used in Linux and Windows.

katemonster33 commented 5 months ago

Fooled around in the options a bit. This appears to be an issue related to having the Renderer option set to "software". On opengl setting the problem is gone, the window looks exactly like it does on Windows.

NetSysFire commented 5 months ago

image

My settings, for reference. I am also using the software renderer since ages.

NetSysFire commented 5 months ago

I can confirm that the fonts look so much more crisp on opengl

Qrox commented 5 months ago

I am using direct3d11 and the font also looks blurry. Changing to opengl does not fix it either. My game is compiled with MinGW-w64, if that matters.

katemonster33 commented 5 months ago

@Qrox that's very curious. I believe we've narrowed down this issue to SDL for certain though.

The actual function used by ImGui to draw to the screen is SDL_RenderGeometryRaw . ImGui boils drawing of everything down to one giant draw command that is a large pile of vertices that all reference one giant font atlas texture. I don't believe the 'X' of the window is a font texture so I'm not sure exactly how it works with that function, only that it definitely does all use that.

Anyway, I am only explaining that because CDDA definitely does not use that function anywhere. Maybe what we are seeing is a bug related to that function with certain configurations?

vetall812 commented 2 months ago

Just checked build:

- OS: Windows
    - OS Version: 10.0.22631.4112 (23H2)
- Game Version: cdda-experimental-2024-08-29-0513 673d845 [64-bit]
- Graphics Version: Tiles

in my case ImGui is blurry with any renderer except opengles2 (this one shows only black screen and I have to change settings manually in file).

It can be linked with #75920

Well I managed to remove blur effect, but with side font. OpenGL+font blending works fine for fonts that are not pixel perfect.

sonphantrung commented 1 month ago

75920 didn't quite fully solve the problem as it uses default UI font (Terminus)

image image Probably something with the Catapult's user/game config

IdleSol commented 1 month ago

cdda-windows-tiles-x64-2024-08-30-0310

[EN] 1

[RU] 2

Options menu 3

In the settings menu, English text is less blurred. Russian text is not blurred at all. Most likely because of a different font. Default settings.

vetall812 commented 1 month ago

75920 didn't quite fully solve the problem as it uses default UI font (Terminus)

Probably something with the Catapult's user/game config

I tried to exclude external user settings from this issue and have tests with local game settings as well as font files.

vetall812 commented 1 month ago

75920 didn't quite fully solve the problem as it uses default UI font (Terminus)

try to use absolute paths to fonts for now. (#76057)

juur commented 1 month ago

This is still broken:

from the demo (blurry) image

from the link on the menu to launch the demo (not blurry) image

(Windows, opengl rendered but same under directx)

Lumi-Virtual commented 1 month ago

i did a few quick tests and it seems like imgui is using the vector fallback set of characters from terminus instead of the bitmap characters. except for the question mark character, as well as the russian characters it seems, and so id guess that its only using the vector fallback for like, the engilsh alphabet, numbers, and some but not all of the punctuation characters (since the brackets and period also look wrong)

here i modified the D and the ? in the vector fallback set and only the D changed. you can see how the ? is positioned slightly higher than the rest, which is consistent with the bitmap set of characters compared to the vector fallback set. image

katemonster33 commented 15 hours ago

@NetSysFire please retest now that #76420 has been merged

IdleSol commented 14 hours ago

1 2

I don't really like the fact that the text is in bold. But that's probably because I'm used to the old version.

UPD. cdda-windows-tiles-x64-2024-10-28-0933

UPD2. 3 4

katemonster33 commented 13 hours ago

Looks like the blurriness is gone. If you look closely, the window "X" button is still corrupted

IdleSol commented 13 hours ago

1

UPD. Oh, it's about the game running on windows. I have a windows game running on linux.

NetSysFire commented 11 hours ago

@katemonster33 I am unsure how I am supposed to retest. Yes, the new font looks fine but it also introduces new issues that need reintroduction of a monospace font for some things, e.g gravestones. And if I read that right, the issues lie with some pixel stuff related to that monospace font. So while saying this is fixed now is technically correct, I anticipate it will come back to bite us when the monospace font gets used again, which should be very soon. Of course, this can be incorrect as I am by no means an expert on these things.

Somewhat less related but that X is also mildly overlapping the text, probably related to the ". I have seen this happening multiple times with varying severity. This one is mild though. image

katemonster33 commented 10 hours ago

@NetSysFire I suppose it's up to you since you wrote the issue, but my gut feeling is that the original issue describes a problem where the text on ImGui screens is garbled and barely readable when compared to text on the rest of CDDA. The other issues should get their own issue numbers IMO