Closed NoelFB closed 3 months ago
(M)SDF fonts sound interesting. Raylib supports normal SDF font rendering, and I believe it just uses stb SDF rendering. It may be lower lying fruit/smaller dependency than full MSDF.
yeah SDF fonts are much easier to add since stb_truetype has it built in ... could be worth dropping those in along with a default shader for them.
I implemented a first pass of this. SpriteFont now dynamically updates internal texture pages as characters are requested, so you no longer need to feed in what characters you need ahead of time. I'm sure there's issues, but it's functional!
I think it could be useful to dynamically render more characters as requested. In languages with a lot of characters (Chinese, Japanese, etc) it can make more sense to render characters as needed, instead of having to determine everything upfront.
This would probably work by creating some kind of queue to render characters off the main thread as requested, and then updating the SpriteFont's Texture each frame if there are more characters that have finished being rendered. If you draw a character that hasn't been rendered yet, it could add it to the queue and then just show nothing until a future frame. If you want to avoid a few frames of text "pop in" there could be some way to request characters ahead of time.
I'm not sure if this should just be part of SpriteFont, or a different DynamicSpriteFont class entirely. It needs to be more complicated (ex. rendering characters off the main thread, updating the main texture on the main thread each frame, etc).
Alternatively, if this feels overly complex for the framework, this could just be entirely left up to the end user. SpriteFont already has a way to add user-created characters.
I'm also potentially interested in adding MSDF fonts, which I have working nicely in some non-Foster projects. But they require including a C++ library, and don't work with a lot of fonts without modification.