What is currently the best smoothest way to render fonts?

Hello Odin Forums,

Hi Bill and other Odin users. I have been learning Odin for the past 2 week and absolutely love it.

I wanted to ask you guys what’s the best current way to render fonts with all bells and whistles like subpixel rendering and anti-aliasing etc.

I want the font rendering to work across backends like OpenGL Vulkan DirectX and Metal. (or if I’m being too optimistic, just OpenGL)

i wanted to try TrueType but the only github project is currently unmaintained.

Let me know.

I don’t know if this is the best way, and I haven’t gotten around to doing proper font rendering in my own applications yet, but you could probably use sdl3/ttf which is in vendor. I haven’t used it myself but since no one else has answered I figured I may as well.

EDIT: I guess you could also use raylib to do it.

1 Like

The closest to a permissive library that is as professional as you can get in the open source space will be Harfbuzz (for the text shaping) and FreeType (for font loading / rasterization). Both can bind in Odin. You need to build your own font atlas, texture rendering and layout positioning, but as you want to use this for multiple back-ends this is likely your best option.

TrueType is useful as its a “quick and easy” library, but for professional text rendering, FreeType is the way to go. Just beware the memory runtime demands of FreeType + Harfbuzz. Fine for most modern systems. But also beware the complexity of FreeType & Harfbuzz. I use it in my project, it’s not the easiest to understand but you will find the easiest path to be to use FreeType for loading files, Harfbuzz for reading the font tables supplied by FreeType, and using FreeType as the rasterizer. Harfbuzz has more complex rendering techniques but are considered challenging to learn, but it depends on your goals really. If true “clear type” rendering is your goal, Harfbuzz rendering will give you better results overall than FreeType’s rasterizer, but FreeType is still good for most use cases and perfectly fine for text rendering. Harfbuzz is more optimized for memory than FreeType should you choose that route for your text rendering instead - Harfbuzz gives you more tools and GPU rendering in version 14, but I haven’t personally used that so I wouldn’t know how it works or if it’s worth the trade off.

TrueType is not a library as far as I know, it’s a font format. FreeType is a library used to render TrueType (.ttf) fonts. Also sdl3/ttf wraps over both FreeType and Harfbuzz. Is that not good enough for some reason?

My bad, I was thinking stbtt which I refer to as the TrueType library. And no, I wasn’t aware that sdl3/ttf used FreeType and Harfbuzz underneath. But if you wanted to use SDL3 for text rendering I guess that’s fine if that’s what the OP wants, but they were suggesting using multiple different back ends like DirectX so I suspect not?

I don’t know much about SDL though so I don’t know if SDL3’s own TTF rendering can be used cross-driver, so if you think it’s better than using FreeType/Harfbuzz directly, then sure, why not.

You can use it with SDL_Renderer which I believe is cross platform. I don’t think you can use it with a custom renderer you wrote yourself but that’s probably not what most people want.

EDIT: Actually it seems like you can use it with a custom renderer. SDL3_ttf/TTF_CreateGPUTextEngine - SDL Wiki and SDL3_ttf/TTF_GetGPUTextDrawData - SDL Wiki I stand corrected.

1 Like

Yes, most graphics libraries support cross-blitting with their own GPU handles. But that approach carries its own risks. You either need to blit your draw data once to a single texture handle and blit that (not very flexible and you may lose graphics quality due to the different blitting techniques per graphics vendor), or read the glyph handles directly from SDL (assuming it provides it) and blit directly into your custom renderer. The latter is probably the most robust solution but kind of defeats the point of using SDL’s TTF addon at all.

I’ll have to look more into it later. For now, I’m just guessing so it doesn’t feel right for me to make too many assumptions.

Ok. I’ll check it out. This currently looks perfect.

This project might be too big of dependency (includes harfbuzz), but Skribidi is a great library to handle all kinds of text layouting and shaping.

The rendering will be your responsibility, but I found it to be straight forward. Note that I already went through text rendering tutorial of opengl, that’s why I found it easier.

Someone mentioned a new UI framework for Odin on reddit, called Skald. And the lib author build his own font renderer called Runa. But I have not tried it yet.