View Full Version : Fonts
kerchen
12-06-2002, 05:10 AM
So, what do people do about fonts in their games? Since I expect to have a fair amount of text in my game, I can't pre-render all my text to bitmaps, etc. Also, I want to have the option of easy localization of my game to other languages, so having text embedded in my art assets isn't a good idea anyway. Therefore, I need to be able to render arbitrary text at runtime.
I've been checking out different options and the top contender thus far is Pyrus' FONMaker (www.pyrus.com). FONMaker essentially takes a TrueType font and renders it to a FON file, which I understand to be a bunch of bitmaps representing each glyph. Then, I simply use Windows API functions to render my text to the screen. Are there any legal "gotchas" with redistributing bitmap representations of copyrighted TrueType fonts? From what I can figure out, this should be okay, legally speaking. Is there something better than this out there that's reasonably priced or, even better, free (FONMaker costs $100)?
I like to use Bitmap Font Builder (http://www.lmnopc.com/bitmapfontbuilder/) for simply creating a text 'texture'. Then I use my own routines for rendering the text.
That's one of the best features of my engine - 3d-accelerated text!! ;)
Dan MacDonald
12-06-2002, 05:50 AM
If your using directx(D3D) the SDK has a sample of a class that renders a true type font to a texture and allows you to draw strings on the screen as textured polys....
elund
12-06-2002, 09:49 AM
I wrote my own font code. I created images in Paintshop Pro with the TrueType font I wanted, using a widely-spaced ASCII-ordered string (e.g., ... 7 8 9 : ; < = > ? @ A B C ...). I then touched up the images so that there are no in-character gaps, usually just the "double quote" character needs a touch-up. Some fonts are lacking characters, but most replace the missing character with a period so my program still works. For some images I applied border or embossing effects. Then after my program loads the font image it scans for the gaps between characters, and stores the width and starting location for each. Writing a font string becomes a simple matter of looking up the ASCII value in the table, to find the location of that character in the font image, and copying that part of the image to the desired surface. It works pretty fast, and it's easy to create new fonts. Originally I was planning to create a utility pre-calculating the character positions and widths and storing them in a file, but the scanning happens so quickly it's become a low priority. I was also thinking I should have the utility eliminate the space between characters, but I've decided the reduction in file size will be negligible. The font file itself is small, 3-4K for a PNG.
I don't know how legal this is, but since the fonts I'm using I paid for or are listed in the public domain, and I'm not distributing the actual TrueType file, I think I'm ok.
Dexterity
12-06-2002, 10:57 AM
I do something similar with bitmapped fonts, except that I go a step further. I wrote a font ripper utility to pre-process and compress all the font data letter by letter. I also store the kerning pair data for each font (which you can retrieve via a Windows API call), and I manually adjust the kerning data for certain character pairs so that the spacing looks right. It usually only takes about 20-30 minutes to get the kerning for every character in a font to look just right, since only about 5% will need to be adjusted.
My raw font bitmaps are stored as grayscale TGA files with an alpha channel. Since the fonts are stored as raw monochrome data, I can render them in any RGB color on the fly, and they're automatically anti-aliased.
I did have to write my own text formatting functions for things like paragraph formatting and justification, but this only took a few hours, and the coding is fairly straightforward. The nice thing about bitmapped fonts is that they look the same on every system. If I want to translate the game to other languages, all I need to do is to render out more fonts in those languages.
svero
12-06-2002, 04:46 PM
I also have a bitmap font format which I edit using paint shop. The font ripper sounds nice though. I need one of those :-)
Fenix Down
12-07-2002, 07:36 AM
I adopted NeHe's (http://nehe.gamedev.net) bitmap font routines for my graphics engine. I think without using some sort of third party library you can't have cross platform fonts any other way. Not that everyone wants that (especially Microsoft) but I certainly do. :)
bernie
12-07-2002, 01:31 PM
Well, fonts are kewl. :) My engine uses freetype2 to render the glyphs at runtime. It renders a 256x256 bitmap and saves all other data like offsets, kernings to a general font object. My font module only passes a sprite and a [x, y] coordinate pair to the graphics layer. Of course my graphics layer also abstracted so it easly supports every available graphics platform.
Why I recommend using a proven font engine? Well, to separate yourself from Windows! Freetype supports wide variety of platforms. And the binary distributed font allows people easly mod your stuff. Being it a new language mod or gothic module for your puzzle game. Unfortunately the freetype.dll weights about 197k compressed, so there is a price.
I still use some legacy font and code from the DOS time but only for debugging and developing.
Fenix Down
12-07-2002, 02:28 PM
Yeah Freetype is good as I hear. Even Blizzard Entertainment uses it. Another thing I recommend is ZLIB (also used by Blizzard). It lets you read ZIP files, so you can just compress all your data into a zip, rename it to something else which should prevent most people from getting to your stuff, and you have a simple archive system without a lot of work.