Rendering text with harfbuzz/freetype

I’ve added a lookup table to reuse textures. This allows me to not allocate new Textures in each loop iteration and I think solves the memory leak (Though I guess I still need to go through the Hashmap values and unload them at the program exit).

Maybe more interestingly: After playing with the numbers in setCharSize the font now looks like this:
image

That’s for this configuration:

    // ToDo: understand these magic numbers
    try ft_face.setCharSize(0, 5000, 9, 35);

The texture lookup looks like this:

    var textureHashMap = std.hash_map.AutoHashMap(u32, rl.Texture2D).init(std.heap.page_allocator);
    defer textureHashMap.deinit();

...
            const maybeTexture = textureHashMap.get(info.codepoint);
            var texture: rl.Texture2D = undefined;
            if (maybeTexture == null) {

            // create new texture from glyph bitmap
            // ...

So maybe now all that’s left is figuring out how to parametrize the face correctly? I saw there’s also a call for setting pixel sizes: freetype2 - Setting Character Size in FreeType - Stack Overflow

1 Like