iDevGames Forums
Fonts in OpenGL - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Fonts in OpenGL (/thread-7696.html)

Fonts in OpenGL - monteboyd - Jun 19, 2002 06:23 PM

As I am getting closer and closer to finishing my snowboarding game (beta v2 on the way soon!) I am starting to think about my other project which I put on hold.

I'm basically starting from scratch on it with the world editor being my main focus as it will bring together all the elements of the engine. I'm considering doing the entire interface in OpenGL to take advantage of hardware acceleration always getting better. My main problem with this would be drawing text. Up until now I have always just used DrawString() which worked fine, so what would an OpenGL alternative be?

I've noticed that Apple has some example code for drawing strings by generating textures from a font, is this a good way to go?

I'm just open to ideas at the moment, development is not starting for a little while yet.

Fonts in OpenGL - Nimrod - Jun 20, 2002 04:58 AM

I made a custom GUI for my editor (which is cross-platform), and although it allows for any graphics platform, OpenGL is the only implementation I've made. You can do this to build display lists for each letter (i.e. what you mention):

GLuint myFont = glGenLists( 96 );
short fontNum;
GetFNum( "\pLucida Grande", &fontNum );
aglUseFont(aglGetCurrentContext(), fontNum, bold, 12, 32, 96, myFont);

and to draw a string:

glPushAttrib( GL_LIST_BIT );
glListBase( myFont - 32 );
char[] myString = "I am therefore I sleep";
glCallLists( strlen( myString ), GL_UNSIGNED_BYTE, myString );

I tried to do it a really fancy way and use FreeType, but I couldn't get it to render as nicely.

Fonts in OpenGL - OneSadCookie - Jun 20, 2002 01:14 PM

aglUseFont is dodgy at best, useless at worst, and officially unsupported in Carbon.

I've had very good results texturing from FreeType; I can post a demo if there's interest. It's not very difficult to use.

If you're using C++, have a look at FTGL ( It puts a C++ interface over FreeType, and lets you draw your fonts as bitmaps, polygons, textures, outlines, &c.

Fonts in OpenGL - Nimrod - Jun 20, 2002 01:40 PM

I'd be interested to know how you used FreeType yourself. I just blitted as many characters as I could to a 256x256 texture, then uploaded it, but recording where in the texture each character was. To draw I used the appropriate positions to texture a rectangle for each character. I can't remember clearly (can't access this stuff atm), but I think the ugliness of the rendering was caused by letters overlapping, thinking of it I could have just spaced them out more.

Obviously doing it this way you don't get the features like kerning that Freetype offers.

Did you do it this way, or blit the characters every time you want to render text?

Cheers Grin

Fonts in OpenGL - OneSadCookie - Jun 20, 2002 04:53 PM

Yeah, I just blit the characters every time I want to render text. It's fast enough for titles & labels and things, particularly if they don't get updated too often Wink I don't even have any caching set up at the moment, though that should be easy enough to implement.

I think FTGL uses your technique, though.

Fonts in OpenGL - henryj - Jun 20, 2002 08:16 PM


If your going to be mac only I'd have a look at the Apple sample code. They've got a good screensaver that shows text quite nicely.

FTGL will be a heap easier to use though. The down side is that you will have to install freetype. This maybe a little less painful soon. I've heard on the grape vine that there may be a freetype framework available soon.

Nimrod -

For some reason doing it the aglUseFont way is really slow. It's a dog.

Have a look at FTGL. The pixmap and bitmaps are just blitted to the screen. The texturing stuff builds the texture on the fly only creating letters when they are needed. All the letters are kerned. It's open source so steal just the texturing stuff if you want.

Fonts in OpenGL - swcrissman - Jun 21, 2002 02:48 AM

I'd be interested in seeing a demo with free-type and/or TFGL. I've had limited success getting good results, and I'm sure its because of the way I'm using it.


Fonts in OpenGL - ylaporte - Jun 21, 2002 08:27 AM

I used the sample code Alphabet on apple's website to render text for my game console. It works fairly well, I do cache the lines that are unchanged tough.

However, this doesn't allow to do anything fancy such as 3D fonts.

Fonts in OpenGL - OneSadCookie - Jun 21, 2002 03:20 PM

FTGL comes with a demo program showing off its capabilities. I think you'll be impressed.

Fonts in OpenGL - Nimrod - Jun 23, 2002 10:57 AM

Anyone tried using Freetype with Codewarrior? When I originally wrote a little test app, it was on the PC with CW7 for Windows, and that worked fine. Now I'm trying to get this to work with CW7 on the Mac, but there are problems with the header includes. Freetype tries to be clever by using macros to detect which headers it should include, but CW for mac doesn't seem to like it.

This is the error message I get:

Error: the file 'freetype/config/ftheader.h' cannot be opened.

So, I turn on 'Interpret DOS and Unix paths'. And it gets an error when it tries do #include "FT:include/freetype/config/ftconfig.h". The error message says that file cannot be opened.

Grrr... will I be forced to use PB to get this working?


Fonts in OpenGL - OneSadCookie - Jun 23, 2002 01:19 PM

You do need the "interpret DOS & Unix paths" option, and you'll also need to ensure that the directory that contains the "freetype" folder is in the header search paths.

I think that FTGL has a CodeWarrior project, so you could probably just steal the settings from that Smile