How do you render your game engine text?

Started by
5 comments, last by RobM 3 years, 11 months ago

Hi

How do most people render fonts in their engines? For a while now I've been rendering a quad containing the entire text and passing a constant float buffer containing the letter lookups in a long 1536 x 16 texture but I seem to see a few other people rendering a letter at a time in character-sized quads. My thought is that for a whole line of something like debug info (or in-game info), you're increasing your draw calls by the number of characters even though the geometry is simple and probably locking/unlocking vertex buffers and changing uv coords for the font lookup for each character quad. My drawing a quad large enough to cover the entire text and passing a constant buffer containing the letters seems more efficient but I see a few glitches in the uv coords that don't look great. Not sure if this is to do with floating point errors but I'm thinking about switching to the draw call per letter method to see if it helps.

Any thoughts?

Thanks

Advertisement

Rendering a quad per letter is ineffective. My guess is people do this because popular tutorials show it that way. In my simple text renderer i have two draw calls, one for the labels and one for the changing stuff. Are you sure your glitches don't come from an off-by-one error when assembling the texture or when looking up into it or some such ? It took me days (well hours) to figure out all those offsets :-) It shouldn't flicker …

@Green_Baron Thanks for the reply. Yes, I just fixed my texture glitch. I had just ported my engine from DX9 to DX11 and I didn't realise we no longer need the 0.5 texel offset, removing that worked. Rendering one quad per line of text seems pretty efficient.

Cheers

Personally, I just render the text in software, upload the resulting image as a texture and then render the text as a single quad. I've considered uploading the entire font as a single texture and then building a mesh that uses that texture to place individual characters, but that would require an insanely huge texture (143,859 unicode characters × 16×16px per glyph × number of variant glyphs per character × variants for italic and bolded text > 12000×12000 just for one font at a fairly small text size).

Something that renders each character as it's own quad ends up generally being bad at things like kerning, ligatures, and context-dependent character shapes. These are important in high-quality text, but kind-of don't matter for simulated sci-fi console logs …

I prefer to render full lines of text into an in-RAM bitmap, and upload the full line into some available texture space, and then, when rendering on screen, use a single quad that blits that full line impression. Obviously, I'll want to keep cached copies of lines of text that are drawn the same every frame, whereas things like FPS meters just get rendered each time they change (which generally isn't every frame, anyway, because they're rounded to, say, 1/10th of a fps.)

If text is really important to you, and if you have at least some budget, I highly recommend checking out the Slug library. It's a commercial library, with a variety of different licensing models available. It's written by one guy, so you can negotiate a lower cost if you're an indie game. Slug renders vector fonts, with all the fancy kerning and such, as geometry. It's extremely fast, extremely flexible, and very pretty.

enum Bool { True, False, FileNotFound };

hplus0603 said:

Something that renders each character as it's own quad ends up generally being bad at things like kerning, ligatures, and context-dependent character shapes. These are important in high-quality text, but kind-of don't matter for simulated sci-fi console logs …

I prefer to render full lines of text into an in-RAM bitmap, and upload the full line into some available texture space, and then, when rendering on screen, use a single quad that blits that full line impression. Obviously, I'll want to keep cached copies of lines of text that are drawn the same every frame, whereas things like FPS meters just get rendered each time they change (which generally isn't every frame, anyway, because they're rounded to, say, 1/10th of a fps.)

If text is really important to you, and if you have at least some budget, I highly recommend checking out the Slug library. It's a commercial library, with a variety of different licensing models available. It's written by one guy, so you can negotiate a lower cost if you're an indie game. Slug renders vector fonts, with all the fancy kerning and such, as geometry. It's extremely fast, extremely flexible, and very pretty.

Thanks for the suggestion, I'll check it out.

This topic is closed to new replies.

Advertisement