PDA

View Full Version : Advice about fonts



cragwolf
02-05-2005, 06:48 AM
I have 3 days off in a row starting tomorrow so I'm going to code like a madman. What I want to work on during these days is font output with OpenGL. I want a platform-independent solution, so I think I'm going to go with the textured quads approach. The fonts will be defined in some texture, and then drawn to the screen on a quad using the appropriate texture coordinates for each letter. Anyone here done this before? I imagine that I have to draw the text last, after everything else in the scene, and also that I should probably switch off depth testing when I'm drawing the text. Is that the right idea?

Also, what sort of tool(s) would I use to generate the font texture? I imgaine that it would be tedious to use Photoshop or the GIMP to generate each character and then manually stitch them together into one texture. But I guess this only has to be done once for each texture set. I'm thinking of using the alpha channel so that the text blends in with whatever is in the background. That would be nifty.

Sly
02-05-2005, 07:00 AM
I use Angelcode's Bitmap Font Generator. It creates great quality font textures with a data file that details the position of each character in the texture.
http://www.angelcode.com/products/bmfont/

There is also some pseudo code on that page showing how to draw a character. BMFont now also gives you the option of using the alpha channel for the font image (the RGB channels are all white). This gives the best results when blending over a background.

cragwolf
02-05-2005, 09:40 PM
Hey, that's a neat little app.

Almindor
03-05-2005, 08:01 AM
Perhaps it's not what you're looking for but after trying a few strange "image to test" libraries I ended up with good old fashion TTF. It works ok SDL_TTF on most platforms/archs if you provide the font(note: M$ fonts are nicer but do not follow standards)

The only problem I had was with special chars of my language. But this is more like a ISO-2 vs CP1250 encoding problem than anything else(even getting mplayer to play the subtitles right is a killer)

{MSX}
03-05-2005, 08:06 AM
I'm using this tecnique to draw fonts. I usually switch off depth testing and also switch to an ortographic projection. I use bitmap monosize font, that enables you to keep the code simple. With variable size fonts you have to work out some way to save characters width..
There are also some libraries with SDL to deal with font, you could eventually look at them.

Sly
03-05-2005, 09:15 AM
http://www.users.on.net/~sly/images/bfauto3.jpg
shows the results of using BMFont and the pseudo code provided with it.

No code page/encoding issues. No malformed TTF issues. Works the same everywhere. Works with proportional fonts as well as monospaced. Also works with fonts that have overhangs.

It is also how 99% of commercial games do fonts.

savage
03-05-2005, 10:20 AM
Pity we never got to see you finished PGD competition entry.

M109uk
03-05-2005, 04:56 PM
Hi,

I use my own font system, its based upon Nitrogens Font Studio 2, but has been modified so that you can either choose a windows font and it will generate the bitmaps or it can be stored in a file and loaded that way. There is also a little form of formatting, you can add Bold and Italic to it as well as colour the captions..

Some screenshots can be found here:
http://www.bio-sphere.org.uk/index.php?action=screenshots&d=XShell%2FFont+Viewer

And it can be downloaded here:
http://www.bio-sphere.org.uk/index.php?action=downloads&d=XShell%2FSDK%2FTools

Its still WIP and i havnt had time to carry on with it...

Sly
03-05-2005, 11:58 PM
Pity we never got to see you finished PGD competition entry.

Yes, it is. It looked and played great in my head though. :D

I think the grand plan may have been a bit too ambitious overall, considering that I was writing my own engine from scratch at the same time and wanted to create all the graphics/models from scratch. It is still on the back burner though.

savage
20-05-2005, 12:34 PM
Just to let you know that with some inspiration from MSX, I wrote an OpenGL SFont demo last night which is now checked into the JEDI-SDL CVS.

I have a slight colour issue, which I am sure is due to the way I am creating my SDL_Surface for the text, but for all intents and purposes it works exactly like the SDL_ttf demo called glfont. Hopefully in the next few days I will sort out the colour issue.

More info about SFont can be found at http://www.linux-games.com/sfont/, with the difference being that the JEDI-SDL version is a 100% pascal port of the v2.x C code, so no DLLs or SO needed. If you use The Gimp you can get an SFont generation script from http://www.linux-games.com/sfont/.