-
Notifications
You must be signed in to change notification settings - Fork 0
FTGL
The GUI uses OpenGL for data visualization. However, OpenGL doesn't have any functions for drawing text. The typical solution would be to use GLUT to render text, but this has two drawbacks: 1. GLUT is not open source and 2. GLUT fonts are ugly, inflexible, and hideous. Did we mention they aren't pretty?
Fortunately, there's FTGL, a free, cross-platform, open-source (MIT/LGPL) C++ library for rendering fonts in OpenGL.
You can install the FTGL development files with sudo apt-get -y install libftgl-dev
If you'd rather build from source, you can get the code via Subversion (svn co https://ftgl.svn.sourceforge.net/svnroot/ftgl ftgl) or from SourceForge. Installation involves running ./autogen.sh, followed by the standard ./configure, make, sudo make install sequence. You may have to install GNU autoconf, GNU libtool, or FreeType2 to get it to work, but otherwise installation is straightforward.
In return, you get gorgeous anti-aliased text in your OpenGL components, using any TrueType or OpenType font on the planet.
Once the fonts are loaded, it only takes three lines of code to draw your characters:
- Choose a location in the viewport:
glRasterPos2f(float, float); - Set the font size:
font->FaceSize(int); - Tell it the characters to draw:
font->Render(String);
Loading fonts is also a three-line affair (once the fonts are stored in BinaryData.cpp):
const unsigned char* buffer = reinterpret_cast<const unsigned char*>(BinaryData::fontname_ttf);size_t bufferSize = BinaryData::fontname_ttfSize;FTPixmapFont* font = new FTPixmapFont(buffer, bufferSize);
<< Back to Opal Kelly | Continue to Installation >>