News for hackers. Stuff that matters.
Re:Complex text layouts progress report in Godot game engine by londons_explore on Tuesday November 10, 2020 @09:52AM (#25046574)
Why do game engines need their own text engines?

Why not just use some system library to write into a texture and then use that in your game?

Re:Complex text layouts progress report in Godot game engine by klodolph on Tuesday November 10, 2020 @10:07AM (#25046756)
You can do that! I've done it. I tapped into Uniscribe on Windows, Core Text on macOS, and PangoCairo on Linux. The problem is that this looks horrifically inconsistent between platforms. You also end up doing a ton of work to figure out how to accomplish a simple task like, "I want this text in this box, that word is italic, please add the line breaks, here is a font file." That's simple on one platform, but you end up having to duplicate everything you do across all the platforms you support, and typically you will find one platform that breaks your assumptions about how libraries should handle this task. Your code ends up being convoluted so it can hide the (major) differences between different APIs.

It's actually so much work that you probably want your game engine to do it internally in a way that is consistent cross-platform. Fortunately, most of the guts have already been figured out for you by the amazing people that work on HarfBuzz. The basic formula is to take your Unicode string, take your font, and feed it to HarfBuzz to have HarfBuzz figure out the metrics and glyph offsets. You then use the metrics to do layout and line breaks.

It is a lot of work, but it turns out to be less work than figuring out how to this working cross-platform using system libraries. This is also, generally speaking, how web browsers deal with their text. There are a couple other pieces that you need like text segmentation but these are tractable.

Re:Complex text layouts progress report in Godot game engine by jcelerier on Tuesday November 10, 2020 @04:15PM (#25052019)
> Why not just use some system library to write into a texture and then use that in your game?

if you are making any non-trivial software that is supposed to run on two different operating systems, you never never never want to use the OS font rendering, as you'll get text slightly wider, line breaks at different places, stuff that fits neatly in a pixmap on Windows will be 3 pixels too wide on macOS and suddenly won't fit your button, baselines are a bit different, there's the 72 / 96 dpi mess, users will complain that their document don't look the same across OSes... it's an endless can of worms. Just ship & use freetype & harfbuzz everywhere (or use Qt which can do that for you automatically).

Re:Complex text layouts progress report in Godot game engine by gameswithgo on Tuesday November 10, 2020 @11:30AM (#25047789)
that is what you do a lot of times. but then what if the user resizes the window? do you just scale the texture and let it look like crap? do you draw new textures on resize events? same question RE user changing font size. what if the game has lots of varied font sizes. now you have a lot of textures. what if the font has features that depend on adjacent letters? then you can't just render every letter and slap them on the screen as needed when people type.

fonts are hard

Re:Complex text layouts progress report in Godot game engine by morelikeborelax on Tuesday November 10, 2020 @09:57AM (#25046644)
Because Godot is OS independent for development and consumption so there would be inconsistencies.
Re:Complex text layouts progress report in Godot game engine by Deukhoofd on Tuesday November 10, 2020 @10:00AM (#25046687)
Because we do not want games to require fonts to be installed to properly render.
Re:Complex text layouts progress report in Godot game engine by flohofwoe on Tuesday November 10, 2020 @10:17AM (#25046849)
What system libraries would that be? Windows has DirectWrite, but AFAIK on other platform (or even web browsers), the situation is dire.