3 ms·
Back when I was making games (and game engines), whenever I had to render text, I used freetype to render to a memory buffer, and uploaded that as a texture. Tw
by ggambetta 8y ago
Back when I was making games (and game engines), whenever I had to render text, I used freetype to render to a memory buffer, and uploaded that as a texture. Two triangles / one quad per "label".
For this use case, where text labels don't change that often or are that many, the approach suggested in the article (two triangles / one quad per glyph, and having to do kerning by hand) sounds unnecessarily complex.
- jchw 8y agoDepends on lots of factors. I often used that approach too, but it has its downsides: uses a relatively large amount of texture memory, text can't be scaled, not really compatible with subpixel rendering¹. An example of another technique would be signed distance fields, which is useful for putting vector shapes like fonts into 3D environments without using high resolution textures. It has the property that you can transform the result fairly effectively, avoiding artifacts from antialiasing and pixelation. 1. Though it's pretty hard to avoid that since you really need to be able to do the alpha blending yourself.
- planteen 8y agoWere you still rendering individual glyphs into a font cache and then rendering those textures into a single text texture? It seems like it would be pretty expensive to always render each individual glyph from the font engine every time instead of caching the results.
- ggambetta 8y agoNo, just rendering the string every time it changed. For the kind of games I was making, text didn't change that often, so caching it worked fine.