FTGLES Update (or, truetype fonts for OpenGL ES)

FTLGES on github: http://github.com/cdave1/ftgles

FTGLES on iPod Touch

I’ve been working on a library called FTGLES, which is an open source truetype font rendering library for OpenGL ES 1.1. FTGLES is a port of FTGL, a library originally written by Henry Maddocks and a number of other contributors.

Earlier versions of the FTGLES library, originally hosted on googlecode, were horribly buggy. OpenGL ES is essentially a stripped down version of OpenGL. To get FTGL working on OpenGL ES, I had to rip out all the old OpenGL calls in FTGL and replace them with a sort of internal “glue” layer that maintained its own internal vertex, texture, and colour buffer arrays. Most of the nasty bugs were caused by the glue layer not restoring client states or buffer arrays properly, and I was repeatedly getting emails from people saying that seemingly unrelated feature x or feature y was crashing their app. I received a number of patches that kinda solved these problems, but they did not quite solve the problems in a way that would work for all users.

I’ve now gone through the library and fixed the these bugs. This updated version will properly restore all previous array and client states. I’ve removed the need to call ftglInitImmediateModeGL() before rendering your fonts. I’ve also added support for polygon font rendering.

Performance is slightly better on this update, but I’m still not quite happy with it. There are always significant performance constraints on mobile operating systems so it’s always going to be a fight to get decent performance. The library will render texture fonts without too much fuss, but polygon fonts should be used sparingly. Unfortunately, OpenGL ES does not allow pixels to be rendered directly to the framebuffer, so the ultra-fast FTPixmap type is still not available. I’m working on a separate type that mimics the behavior of this class by rendering glyphs to single texture, precalculating the glyph texture coordinates, and then using this single texture to render the font so glBindTexture(GL_TEXTURE_2D, handle) does not need to be called for each and every glyph.

The project has now been shifted to github, so if you are interested you should download/clone it from here. I should point out the contributions made by James Long, who did a great writeup on the library here. He re-instated the automake files, among other things, that I removed from the earlier googlecode version for some stupid reason.

The source code contains a number of demos for the iPhone. I’m hoping to provide demos for the iPad, but the most important thing now is to get a version working on the Android operating system. Here is a screenshot of one of the iPhone demos:

FTGLES screenshot on iPhone

Leave a Reply