When should fonts be rendered?

Started by
4 comments, last by Hodgman 6 years, 11 months ago
In my system I have a tool that renders fonts and creates an image file and an atlas file which my game engine then loads. Is this the right way to do things? Should I render the fonts at runtime instead?
Advertisement

Doesn't the current Win10 window manager render GDI to texture anyway? I've read that in window mode directX is drawn on top of GDI for each window. That my be dated? Alpha could be a problem. Fullscreen without fiddling with the screen resolution should be easy. Do it like for GDI and then turn of borders. The current window manager is double buffered anyway. Otherwise any browser animation would look horrible. I dunno if this subpixel LCD optimization still shines though. Same with Apple or Linux after X. (Or amiga for what its worth)

In my system I have a tool that renders fonts and creates an image file and an atlas file which my game engine then loads. Is this the right way to do things? Should I render the fonts at runtime instead?

Rendering sprite font is an optimization.

Usually it's cheaper to render a quad for a letter, than create it each time.

Creating off-line font texture usually decreases your game startup.

The next step of optimization - is to render all letters in one draw call (via instancing).

But it's better to have some GPU profiler before change in implementation.

@Happy SDE I thought my current approach would decrease start-up time. Isnt loading an image faster than rendering glyphs onto a texture?

@Happy SDE I thought my current approach would decrease start-up time. Isnt loading an image faster than rendering glyphs onto a texture?

I got 4 different fonts in one 400 kb texture.

Pipeline creates it in 0.2 sec.

It takes so long because I use outlines (look at letters: there is a slight dark edge at each letter). It helps to see letters on bright surfaces.

One of optimizations: I need only 2 channels in font texture: color + alpha instead of 4 in RGBA.

The other benefit - I don't need to have GDI on user's machine (probably it is good if I would like to target consoles)

And after all, it takes only 0.009 millisec to render all of these letters in one draw call (look at "StatPass" number).

UPDATE: I just measured time of (load texture + load texture coordinates + create texture).

It takes only 1.8 milliseconds in games startup

So, 1.8 millisec is much better than 200 millisec :)

1OjsxWz.png

It also depends on your requirements. If you know all the glyphs that your game will need, then pre-createing textures is an option... But say you have a chat system in your game where players could type any of the millions of human language glyphs from around the globe, then pre-creating textures is not an option.

If you are pre-creating textures though, there's some expensive quality options available to you. Rendering glyphs at 4k resolution each, generating SDFs and downsampling them to say, 32px glyphs, is really expensive so you wouldn't do it at runtime, but that doesn't matter if you're doing it offline :)

This topic is closed to new replies.

Advertisement