Fonts in OpenGL

Member
Posts: 353
Joined: 2002.04
Post: #1
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.
Quote this message in a reply
Nimrod
Unregistered
 
Post: #2
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):

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

and to draw a string:

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

I tried to do it a really fancy way and use FreeType, but I couldn't get it to render as nicely.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
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 (http://homepages.paradise.net.nz/henryj). It puts a C++ interface over FreeType, and lets you draw your fonts as bitmaps, polygons, textures, outlines, &c.
Quote this message in a reply
Nimrod
Unregistered
 
Post: #4
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
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
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.
Quote this message in a reply
henryj
Unregistered
 
Post: #6
monteboyd-

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.
Quote this message in a reply
swcrissman
Unregistered
 
Post: #7
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.

Spencer
Quote this message in a reply
ylaporte
Unregistered
 
Post: #8
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
FTGL comes with a demo program showing off its capabilities. I think you'll be impressed.
Quote this message in a reply
Nimrod
Unregistered
 
Post: #10
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?

Cheers.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do I flip upside down fonts in FTGL mr5z 4 1,047 Mar 3, 2014 03:36 PM
Last Post: JustinFic
  Bitmap fonts markhula 6 7,993 Feb 27, 2011 12:55 PM
Last Post: markhula
  Anti-aliased bitmapped fonts Jake 12 6,750 Nov 19, 2007 05:02 PM
Last Post: Jake
  shared context breaking FTGL texture fonts akb825 12 6,507 Sep 7, 2006 08:56 PM
Last Post: akb825
  Fonts with OpenGL & GLF Jones 15 7,128 Jul 5, 2006 11:32 AM
Last Post: akb825