Ladies, Gents,
I’m proud to present (JSFiddle) TexFont for Three.js, yet another bitmap-font texturing tool which goes back to the works of Mark J. Kilgard. Some of you may remember Mark as the creator of the famous GLUT toolkit back in the nineties, which opened up the world of interactive 3D OpenGL graphics to mortals with cheap PC hardware. Up to then, this had only been available to owners of ridiculously expensive SGI workstations. I owe him much.
Anyway, this is only a partial implementation of GLUT’s TexFont subsystem, in that it reads *.txf files, displays the complete glyph bitmap (sprite sheet) and/or inserts strings of text as fully 3D, genuine Three.js textured mesh objects.
The API I implemented is very straightforward, and I’ll be happy to answer any questions which may arise.
Disclaimer:
This is really only a demo, and not meant as an example of good coding style. For me this was an exercise in getting familiar with reading from, and writing to data textures.
Besides, I like that oldschool look of low-res, aliased bitmap fonts so much, that I chose to (optionally) emphasise it by overlaying a grid helper having the same resolution. Each grid cell corresponds to exactly one pixel in the TexFont source bitmap …
Even if you don’t share my inclination:
if you can appreciate some pretty arcane pre-nineties-style of C-coding (in the template texfont.c, texfont.h
files), involving byte-swapping, bit-shifting, bit-wise logical operations and even bit-reordering, there may be something in it for you, too.