I display text using OpenGL which is aligned with (2D) objects that can have any rotation on display, making the text also appear at any angle on display. So far I've used FreeType to render raster for each supported symbol to file and load the files into OpenGL as textures at application start.

When the text is rotated (other than 90 degree increments) the hinting goes all bad. My plan so far to remedy the situation is to render a few rotated (transformed) variants of each symbol and linearly interpolate between the two closest variants. As an example I may render variants in 15 degree increments between 0-75 degrees inclusive, and if text is rotated by 5 degrees on display I'd take 1/3 from the 0 degree raster and 2/3 from the 15 degree raster.

...but this is only a theory of mine. Should work if having small enough increments, but if there are too many of them I'll run out of memory resources and making the shader awfully inefficient. I imagine the increment count depends on the pixel size of each symbol which could turn problematic...

So I reach out to the expert community: How to render rotated text with proper font hinting in real-time?

Using OpenGL ES 2.0. Font size ~16pix. If you need more info ask away.

  • $\begingroup$ Hinting is only for vertical or horizontal edges in the font glyphs, so I don't think it'll work for your rotations at all. You might need to use SDF font rendering, or rasterise the vector font each frame. $\endgroup$
    – Dan Hulme
    May 11, 2018 at 9:37
  • 1
    $\begingroup$ @DanHulme "Hinting is only for vertical or horizontal edges" - That would be news to me. Reading the docs I understand hinting as a manual shift of the spline in any direction, sacrificing relative distance preservation between (edge-) features in favor of stronger "main" features, such as the three vertical bars in "m". I don't see why this would be a horizontal/vertical thing only... Guess I gotta re-read some books and articles. $\endgroup$
    – Andreas
    May 11, 2018 at 10:07
  • $\begingroup$ @DanHulme I didn't think using SDF for 16pix font was applicable since many features are optimized on sub-pixel basis. Gonna look at it closer though. Thanks! $\endgroup$
    – Andreas
    May 11, 2018 at 10:13
  • 1
    $\begingroup$ OK, I was thinking specifically of stem hints, and control point hints are also a thing in TrueType. The old FontForge docs have a brief explanation. But the point is, hinting is about fitting the glyph onto a square grid, so that beams cover a whole pixel, so you don't get jaggies or blur. Reorienting the square grid obviously invalidates the hints. $\endgroup$
    – Dan Hulme
    May 11, 2018 at 11:25
  • $\begingroup$ @DanHulme Ok, that makes sense. I would need a separate set of hints for each orientation since which parts of a glyph become beams is in part derived from orientation. Guess I'll have to ask the design department to make a font for each orientation they want to show ;-) Really though, I'll have to look closer at alternative solutions such as SDF. Thanks again. $\endgroup$
    – Andreas
    May 11, 2018 at 11:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.