Custom Fonts

Discussion in 'Programming' started by vulcan-dev, Feb 3, 2024.

  1. vulcan-dev

    vulcan-dev
    Expand Collapse

    Joined:
    Jan 28, 2017
    Messages:
    246
    I've loaded a font from memory and from a file, but when I try to rebuild the font atlas via `onPreRender`, it just breaks. It doesn't crash, but most of the text turns invisible and the console background is completely transparent. I also tried this:
    Code:
    fontAtlas = im.GetIO().Fonts
    im.ImFontAtlas_AddFontFromFileTTF(fontAtlas, "ui/common/Cairo-Bold.ttf", 17)
    
    But I get the same result, so I don't think the issue is the font itself.

    It seems like the engine handles the fonts, and it only creates them once (just before ImGui is initialized).
    Are you able to maybe expose a function for adding & building fonts? I couldn't find one for it, the only font functions seem to be the ones from ImGui.

    Unless there's another way? I'll keep looking just in case, but please do let me know if there is a way to do this already. Thanks.
    --- Post updated ---
    I came across this: IMGUI Settings (beamng.com) (Thanks to Zeit), and it looked quite promising. However, I then saw this:
    I have tried putting the font in `myExtension/ui/common`, and the game does find it, but it doesn't add it to the font texture. Output:
    Code:
      0.83523|D|engine::loadFonts| Loading 14 imgui fonts...
      0.83533|D|engine::_imgui_createContext| Adding fonts to imgui:
      0.83549|D|engine::_imgui_createContext|     'cairo_bold'->'ui\common\Cairo-Bold.ttf' Scale: 1.3  RangeCount: 3
      0.83563|D|engine::_imgui_createContext|     'cairo_regular'->'ui\common\Cairo-Regular.ttf' Scale: 1.3  RangeCount: 3
      0.83577|D|engine::_imgui_createContext|     'cairo_regular_medium'->'ui\common\Cairo-Regular.ttf' Scale: 1.8  RangeCount: 3
      0.83592|D|engine::_imgui_createContext|     'cairo_semibold_large'->'ui\common\Cairo-SemiBold.ttf' Scale: 2  RangeCount: 3
      0.83619|D|engine::_imgui_createContext|     'consola_regular'->'C:\Windows\Fonts\consola.ttf' Scale: 1  RangeCount: 4
      0.83643|D|engine::_imgui_createContext|     'icons'->'ui\common\fa-solid-900.ttf' Scale: 3  RangeCount: 1
      0.83794|D|engine::_imgui_createContext|     'notosans_jp_regular'->'ui\common\NotoSansJP-Regular.otf' Scale: 1  RangeCount: 3004
      0.83872|D|engine::_imgui_createContext|     'notosans_kr_regular'->'ui\common\NotoSansKR-Regular.otf' Scale: 1  RangeCount: 3
      0.84126|D|engine::_imgui_createContext|     'notosans_sc_regular'->'ui\common\NotoSansSC-Regular.otf' Scale: 1  RangeCount: 2506
      0.84296|D|engine::_imgui_createContext|     'notosans_tc_regular'->'ui\common\NotoSansTC-Regular.otf' Scale: 1  RangeCount: 7
      0.84317|D|engine::_imgui_createContext|     'prompt_regular'->'ui\common\Prompt-Regular.ttf' Scale: 1  RangeCount: 3
      0.84333|D|engine::_imgui_createContext|     'robotomono_regular'->'ui\common\RobotoMono-Regular.ttf' Scale: 1  RangeCount: 4
      0.84380|D|engine::_imgui_createContext|     'segoeui_regular'->'C:\Windows\Fonts\segoeui.ttf' Scale: 1  RangeCount: 4
      0.84389|D|engine::_imgui_createContext|     'vcr_osd'->'ui\common\VCR_OSD.ttf' Scale: 1  RangeCount: 4 (This is the custom font, it is found here, but doesn't get added below)
    
      2.06502|D|imgui.fonts| font texture contains 13 fonts. Atlas size: 4096x16384px
      2.06505|D|imgui.fonts|  - cairo_bold           [24.3 px]:    292 glyphs
      2.06506|D|imgui.fonts|  - cairo_regular        [24.3 px]:    292 glyphs
      2.06506|D|imgui.fonts|  - cairo_regular_medium [33.7 px]:    292 glyphs
      2.06507|D|imgui.fonts|  - cairo_semibold_large [37.4 px]:    292 glyphs
      2.06507|D|imgui.fonts|  - consola_regular      [18.7 px]:    465 glyphs
      2.06508|D|imgui.fonts|  - icons                [56.1 px]:     16 glyphs
      2.06508|D|imgui.fonts|  - notosans_jp_regular  [18.7 px]:   3685 glyphs
      2.06509|D|imgui.fonts|  - notosans_kr_regular  [18.7 px]:    388 glyphs
      2.06509|D|imgui.fonts|  - notosans_sc_regular  [18.7 px]:   3220 glyphs
      2.06510|D|imgui.fonts|  - notosans_tc_regular  [18.7 px]:  16064 glyphs
      2.06510|D|imgui.fonts|  - prompt_regular       [18.7 px]:    299 glyphs
      2.06511|D|imgui.fonts|  - robotomono_regular   [18.7 px]:    460 glyphs
      2.06511|D|imgui.fonts|  - segoeui_regular      [18.7 px]:    465 glyphs
      2.06512|D|imgui.fonts| 26230 glyphs totally
    
    I can get around this by putting the font in the game directory (ui/common), but that's obviously not what I want.
    Is there a way to force a rebuild of it?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice