VSFontLib – Very Simple Font Library
With immediate mode gone in core OpenGL versions, so are the vast majority of font libs that worked with OpenGL. Immediate mode was terribly slow, and code wise very extensive. Vertex Buffers are clearly the way to go.
Text rendering is very useful to display information on top of a 3D world. Since I couldn’t find a solution for this problem I implemented a simple one to render bitmapped text. If there are other public libs available out there to add to our applications to perform this task, please let me know and I’ll add a link to them here.
I just needed an application that produced a texture with the characters and a file with the texture coordinates to access each individual character.
I found a solution with an “old” application called FontStudio by Michael Pote. The site (www.nitrogen.za.org) no longer exists but I was able to find a copy on the Classic Web Archive (be patient, it takes a while to load but it will get there).
FontStudio is fairly complete and provides a lot of options for character placement and text effects. It also produces an image with all the chars (and an alpha channel) as well as a XML file with the needed texture coordinates.
The VSFontLib loads these files, image (TGA) and xml, to load the font data. With VSMathLib you can load as many fonts as you want simultaneously.
After these files are processed, VSFontLib is ready to render strings. To make life easier for the programmer, VSFontLib takes care of every detail, from setting the correct perspective so that the fonts are properly drawn on the screen, building VAOs to store the triangles for each char of the sentence, and restore your old settings for the modelview and projection matrices. To handle the matrices, VSFontLib , uses another Very Simple Lib, VSMathLib.
VSFontLib also does full memory and resource (Vertex Array and Buffers) management so you don’t have to worry about it.
History
Version 0.1.0
- Initial release
Dependencies
VSL
- VSMathLib to handle matrices
External
- GLEW to access OpenGL new functionality
- DevIL to load the TGA image with the drawn chars
- TinyXML to load the XML file with the texture coordinates.
Downloads
To download go to VSL Downloads page.

check this font library
http://digestingduck.blogspot.com/2009/08/font-stash.html
What’s with the downloads? I can’t find a source repo and the zip doesn’t contain the header file…
Fixed the zip. Thanks.
Good job! Some minor things:
Don’t call glEnable(GL_TEXTURE_2D), this is only needed when no shader is active.
vsfl.h should also include , as std::vector is used.
should be included before “vsfl.h”, as std::string is used in vsfl.h. A god idea is to always include system files before local files.
Hi Lars,
The glEnable thing … old habits die hard
As for the includes you’re right. I forgot to include both vector and string in vsfl.h. Windows is very relaxed regarding includes …
Thanks!
You should take a look at the Angelcode Bitmap Font Generator, http://www.angelcode.com/products/bmfont/
I’ve seen it used a lot more often than Font Studio. That said, you could likely whip together your own bitmap font generator that works way better than either of those solutions, as they’re both fairly deficient in certain important ways. And yours could be cross-platform and open, plzkthxbai
Hi Sean,
Thanks for the tip. Angelcode’s solution seems very similar to FontStudio regarding both results and options. FontStudio is no longer being maintained, and its almost gone (except from the classic-web-archive) so probably that’s why you see Angelcode more often. There is a nice feature in Angelcode’s solution though, character selection. the As for VSFL, it would only require a small modification on the XML reader.
http://www.freetype.org/freetype2/docs/tutorial/step2.html
Check how FT_Glyph_To_Bitmap works!
Regards, Andreas
Hi,
As far as I could get it that’s for a single char. Is there any function to convert a set of chars to a single bitmap, or do you have to do it manually?
Best Regards,
Antonio
You do it manually by simply placing a for-loop around the call…
Yes, you can do it that way, and then copy the bitmaps to a larger image. But to do it this way I would prefer to have it as a pre-processing stage. Generating textures on the fly would put a cost on the start of the application. Pre made texture atlas, which is basically what VSFL does, is more efficient. I believe that the code could be optimised so that the burden of texture generation can be minimal, but that’s outside the scope of this site. Any volunteers?
You may want to look at FreeType, the core font render library in all Linux distros. It renders the glyph into a bitmap buffer before pasting it. Assigning that buffer to a texture is a simple procedure. Imo you should use that as a backend instead because it’s very proven to work and have a lot of nifty features such as cleartype rendering and what not.
Keep up the good work!
Hi Andreas,
I did have a look at freetype. I settled the current approach because it is simpler, at least it was simpler to me to implement. And FontStudio also has a lot of features, such as cleartype, drop shadows, etc… Freetype could give you more flexibility though because font data is generated on the fly. I used FTGL which was based on freetype, but it uses old style OpenGL.
I assume there is a way to create an image with a set of characters using Freetype? If so then using Freetype in VSFL should be very simple. If this is the case then can anyone point me to a tutorial on how to generate this image?
Best Regards,
Antonio