ofxFTGL and Raspberry Pi

I’m having problems with ofxFTGL and the Raspberry Pi. Given that the distributed libraries in the repository are not compiled for the Pi, I’m using the system installed version under Raspbian (libftgl2_2.1.3~rc5). Once I link to the system libftgl, I’m able to successfully compile the examples. However, no text is displayed :frowning: The fonts seem to be loaded properly (font.loadFont returns true), and the draw loop is being called (evidenced by repeated ofLog messages I inserted into the examples). So there seems to be a problem with the rendering of the text on the Pi (the addon and examples work fine on my Mac and amd64 Ubuntu box).

Has anyone been able to get ofxFTGL to work on the Pi? I’m trying to use this given that I was having major performance problems with ofxTextSuite.


Okay, so duh, it probably doesn’t run because I need the ftgles library instead. Has anyone been able to compile ftgles for the Pi, and/or get ofxFTGLES running on the Pi?

So I have solved my problem, but the solution is rather convoluted. Here it goes…

The Raspberry Pi does have versions of libftgl in the Raspbian repositories. However, if you try and link against them, your app will simply segfault or claim an Illegal Instruction. So they’re a no go.

So we have to build our own version of ftgles. But there’s a problem. The version that is available on github seems to have only been tested on the iPhone. The master is not setup for OpenGL ES 2. Plus, there’s a problem setting the font color, properly…more on that in a minute. So we need to fork it, which I’ve done.

Now, to build this on the Pi, we have to do some things:

  1. By default, the headers are looking for the GLES includes in an “OpenGLES” root. The Pi doesn’t have this; rather, they’re split up into /opt/vc/include/GLES and /opt/vc/include/GLES2. So the first thing to do is to create an /opt/vc/include/OpenGLES dir. Within that dir, create symlinks to the appropriate dirs: ln -s ../GLES ES1 and ln -s ../GLES2 ES2. Now, go into the GLES2 dir and make symlinks as such: ln -s gl2ext.h glext.h, etc.
  2. Go to your ftgles repository. We’re going to dispense with building freetype; the version that comes with OF seems to work fine.
  3. cd ftgles and git co gles2 to move to the correct branch.
  4. We now need to configure things. But we need to update our CXXFLAGS like so: export CXXFLAGS="-I/opt/vc/include/ -DFTGLES2". The define is to enable the GLES2 code.
  5. make and make install. You’ll likely get an error about not being able to build the package config file; I haven’t figured out how to fix this, and it doesn’t affect things, yet.
  6. Your library is now in /usr/local/lib/libftgl.a. You’ll have to add this library to your build process; I simply changed config.make (as I’m using Makefiles).

Now what does this library do? Evidently this command glGetFloatv(GL_CURRENT_COLOR, colors) in FTGLES doesn’t actually do anything on the Pi, so there’s no way to set the font color. The original repository version had the font color set to a default white. I added a new method, SetColor that enables one to set the color and alpha using the usual GL scale of 0.0 to 1.0.

Now we have to move to ofxFTGLES. I’ve also forked this in order to enable access to my FTGLES SetColor method (which in ofxFTGLES is called setColor, and uses the usual OF 0.0 to 255.0 scale). I’ve also added the ofxFTGLSimpleLayout class from ofxFTGL, as well as a setUseDisplayList(bool useDisplayList) method to call the appropriate FTGLES method.

This setup enables consistent framerates on the Pi, unlike ofxTextSuite (which is wonderful for its own uses, BTW).

I don’t have a demo of this yet, but I’ll follow-up with a project I’m working on that uses these libraries and addons.

Any comments on the forking or the code are welcome. If anyone can tell me the proper way that I can include my compiled version of libftgl.a in my ofxFTGLES repository, I’d appreciate it.

1 Like