Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL text rendering methods and trade-offs

Background

I work on the game Bitfighter. We're still compatible with OpenGL 1.1 and compile for OSX, Windows, and Linux.

We use vector graphics for everything, including text rendering and manipulation. We use a slightly-modified variation of 'FontStrokeRoman' from GLUT, which is just a bunch of static lines. We like this as it seems to perform very well, easy to rotate/scale/manipulate. We also allow for in-game chat so text is drawn on the fly.

Problem

We want to use more/different fonts.

We've found several other fonts we like, but they are all TTF-type fonts that are built as polygons (with curves, etc.) instead of strokes or spines. This brings up a few problems:

  • We'd have to use textures (which we've avoided so far in the game)
  • They're not easily resizable/rotatable/etc.
  • Performance is significantly less (theoretically?)

We've experimented with converting the TTF fonts to polygon point arrays and then triangulating the fill. This however has been difficult to render nicely - pixel hinting/anti-aliasing seems difficult to do in this case.

We've even experimented with skeletonize-ing the polygon fonts using libraries like 'campskeleton', so we can output a vector-stroke font (with not much success that looks good).

What should we do?

I know this question is somewhat general. We want to keep performance and text manipulation abilities but be able to use better fonts. I am open to any suggestion in any direction.

Some solutions could be answers to the following:

  • How do we properly anti-alias polygon-based text and still keep performance?
  • Do textures really perform worse than static point arrays? Maybe I have a faulty assumption
  • Can textured fonts be resized/rotated in a fast manner?
  • Something entirely different?
like image 784
raptor Avatar asked Mar 21 '13 17:03

raptor


1 Answers

After some convincing (thanks Serge) and trying out several of the suggestions here (including FTGL that uses freetype), we have settled on:

Font-Stash which uses stb_truetype

This seemed perfect for our game. Rendering performance was comparable to the vector-based stroke font we used - textured quads really are not that slow, once generated, and the caching from Font-Stash helps immensely. Also, the use of stb_truetype allowed us to not require another dependency in the game across all platforms.

For what its worth, this solution was roughly an order of magnitude faster than using FTGL for true-type fonts, probably because of the caching.

Thanks for the suggestions and pointers.

Update

The Font-Stash link above was a fork of the original here. The original has since been updated, has added some of the features that the fork, and can allow different rendering back-ends.

like image 77
raptor Avatar answered Sep 30 '22 11:09

raptor