View Full Version : How do fonts work?
Mickey Crocker
08-03-2005, 05:31 AM
I apologize if any of this sounds jumbled, It's currently 8 in the morning, I'm half asleep and I just got off work.
I was wondering if there is such thing as a font tutorial for programming? Anything that will help me with understanding how fonts work and how to prepare for them in code?
I just don't seem to have a good understanding as to how and what (if anything at all) should be done to make fonts compatible for all Operating Systems (win, mac, linux). Should I use system fonts? If so are all system fonts equally supported on all OSs? Should I include the fonts used and install them on the user's machine? Is there an easy to use editor that would allow me to design my own fonts? (probably not a good idea, but I could give it a shot :p) Do all fonts display as the same sizes on all computers and OSs?
I'm not expecting anyone to answer all of these questions but does anyone know where I could find some good information on this topic that may solve my problems?
ChilledOut
08-03-2005, 06:04 AM
Here's a couple good examples:
http://www.drunkenhyena.com/pages/projects/dhfastfont.cgi
http://www.wadesoft.com/dev.html
I think they're both Direct3D 8, but the concept could be applied to anything.
luggage
08-03-2005, 06:19 AM
I've always used bitmap fonts ( commercial and shareware ) , you have much more flexibility in what they look like.
The quickest and dirtiest method would just be to stick a bunch of images in a directory called a.bmp, b.bmp and so on. Loop through them all and load them in as sprites.
When you display a string just print the required sprite and move on by the width of said sprite. I did say it was quick and dirty.
Really you'd want to make a kerning table and put all the characters into one texture. The letters AW fit together quite closely and look too spaced unless you allow for it. It's all pretty straight forward and there's some tools out there to help you.
Hiro_Antagonist
08-03-2005, 08:09 AM
I used to use DirectX's internal font-drawing functionality. Unfortunately, it not only looked different on different machines, but the letters took up different widths, causing too much wrapping in some cases. What made matters worse is that DX has functions to ask it how wide something is, which I worked into my code to make everything fit. But the returned results were not always correct, causing yet more rendering problems.
I ended up looking at what the popcap framework does with alpha-enabled bitmap drawing, and rewrote that functionality in C#/.NET (our language).
The bitmap-drawing code is amazing. By sucking it up and rolling our own solution, we've had no more probems. Rendering is fully consistant on every machine now, and I was able to add in new functions to our font engine that let us do some stuff easier than DX did.
-Hiro_Antagonist
Mickey Crocker
08-03-2005, 02:37 PM
Thanks for the replies guys. After looking into it I think I may be leaning more towards packing and installing ttfonts with my game.
However, would I need different files for pc,mac, and linux?
For example (I'm not using comic sans, but for an example), if I had comic sans installed on the player's pc for my game, and I ported my game over to mac and linux, would the same comic.ttf file work for all operating systems? Or do I need to have three seperate fonts that are compatible to those OSs alone?
luggage
08-03-2005, 02:49 PM
I don't know but you'd also have to make sure they will render out the right size if you can't get exactly the same font on all platforms.
You'll also miss out on applying nice effects to your fonts like drop shadow, bevels, outlines or any other effects.
Mickey Crocker
08-03-2005, 02:54 PM
I don't know but you'd also have to make sure they will render out the right size if you can't get exactly the same font on all platforms.
That is something I will keep in mind. However I don't think I would want to have different fonts for each OS. I'm kinda hoping that one font file fits all, wishful thinking?
soniCron
08-03-2005, 02:57 PM
I'm kinda hoping that one font file fits all, wishful thinking? Not at all. It's all dependent on the way you render the font and whether you package it with your application or not. If you do, you'll have to make sure you've got the rights to do that.
Mickey Crocker
08-03-2005, 03:00 PM
Not at all. It's all dependent on the way you render the font and whether you package it with your application or not. If you do, you'll have to make sure you've got the rights to do that.
great, that is what I was hoping to hear. Thanks :)
ChilledOut
08-03-2005, 11:34 PM
Thanks for the replies guys. After looking into it I think I may be leaning more towards packing and installing ttfonts with my game.
However, would I need different files for pc,mac, and linux?
You should definitely take a look at FreeType, especially if you want to be cross-platform. It's a library that allows you to use truetype (and other) fonts. It's very easy to use and quite powerful.
I think that using a bitmap font is more consistent and much simpler. I use FreeType as part of a tool I use to render my bitmap fonts however.
Hiro_Antagonist
08-04-2005, 08:05 AM
I think that using a bitmap font is more consistent and much simpler.
I believe it's faster, too. Generally, the skies parted and sunshine entered my life when we switched to bitmap fonts, but maybe you'll have better luck w/ source (.ttf) files than we did.
Also, are you sure you are legally allowed to distribute .ttf files to people who don't have them already? Often times, OS's come with usage licenses for the fonts on them, but fonts aren't free. (In fact, they're rather expensive.)
Then again, people usually get away with making bitmap versions of fonts, and that seems to be okay... I've never been totally clear on when it's okay to copy/use/include a font and when it's not. Perhaps the whole gaming industry is built on illegal font usage?
The one thing that should be okay is using a font you know will be on all systems -- for example, using a standard windows font and only distributing on windows machines. Or, if you can find a truly public domain font, you're set. But I'm not sure what fonts, if any, are truly public domain.
Anyone have any insight into that?
-Hiro_Antagonist
luggage
08-04-2005, 09:40 AM
And they end up looking rubbish too. Seriously - go with bitmap fonts all the way. There's a reason that's what the retail industry does.
soniCron
08-04-2005, 10:17 AM
Then again, people usually get away with making bitmap versions of fonts, and that seems to be okay... I've never been totally clear on when it's okay to copy/use/include a font and when it's not. Perhaps the whole gaming industry is built on illegal font usage?
Anyone have any insight into that? I wish I could cite my source, but I have totally forgotten. From what I recall, only the original font files are copyrighted. If the font is "baked," (rendered to a bitmap) then it is no longer protected. That is, of course, excluding natively bitmaped fonts which can't be redistributed since they are already baked. This is why it's perfectly legal to print a font in a magazine, book, etc. This extends to the digital world as well. So, yes. It's ok to use a bitmap font, as long as it wasn't originally a bitmap font.
And they end up looking rubbish too. Seriously - go with bitmap fonts all the way. There's a reason that's what the retail industry does.
Well, 1/2 of that reason is because they can *afford* to use bitmap fonts. Maybe my experience is different than others, but when I worked at Big Game Company we wasted tons of man hours going over the bitmapped fonts and pixel pushing until they looked right. And when we had to localize into seven other languages, the process started at square one again each time.
Maybe I'm just skeptical, but I don't think I can afford that on my own :(
I'm using Freetype2 myself right now, and if in the end they look good enough and I don't run into any legal issues (fingers crossed), I'm hoping I can ship that way!
Hiro_Antagonist
08-04-2005, 07:18 PM
Well, 1/2 of that reason is because they can *afford* to use bitmap fonts.
There are tools out there that will flatten a font to a bitmap font. I fact, I implemented my font solution without ever touching a single font pixel using the Popcap Framework's font-building tool.
The Popcap Framework has a tool to do *everything* for you, for free, out of the box. And the best part is, you DO NOT have to use the Popcap Framework for your entire game, as long as you write code to load and parse the data file yourself. This is what we did -- I wrote the code myself to parse the data file, load the bitmap font, and blit/assemble the letters into all my text-writing functions. It took me about 2 days or so.
Then again, if you're using C++, you can probably even copy their code to load in and parse these files, though that would trigger the licensing restrictions. (Not a big deal at all. You just have to include the license and "This product includes portions of the PopCap Games Framework (http://developer.popcap.com/)."
More info is a developer.popcap.com.
See, a bitmapped font solution isn't so far out of reach thanks to PopCap! =)
-Hiro_Antagonist
soniCron
08-04-2005, 07:22 PM
There are tools out there that will flatten a font to a bitmap font. I fact, I implemented my font solution without ever touching a single font pixel using the Popcap Framework's font-building tool. I think he may mean "decorated" bitmap fonts. I'm just guessing, however.
luggage
08-05-2005, 05:23 AM
We use Bitmap Font Builder (http://www.lmnopc.com/bitmapfontbuilder/). It generates an image with the characters on (based off a windows font) and you can then drop this into Photoshop and drop shadow\bevel emboss to your heart's content.
You can also get the app to output the kerning data in a simple format.
Just out of interest what languages did you convert to? That you had to start again 7 times? Just the standard ASCII set is usually enough for quite a few languages. Things only get sticky when you run into double-byte languages.
soniCron
08-05-2005, 11:17 AM
We use Bitmap Font Builder (http://www.lmnopc.com/bitmapfontbuilder/). He accepts registrations from FreePSPs.com as a payment method for commercial use? That's very... strange.
Sharpfish
08-06-2005, 08:50 AM
And they end up looking rubbish too. Seriously - go with bitmap fonts all the way. There's a reason that's what the retail industry does.
While not wanting to drag the retail guys into the debate - I have to agree. I do not like to see system/real fonts in games.. it dates them and makes the perception of quality a notch lower... but it's your choice :)
I think he may mean "decorated" bitmap fonts. I'm just guessing, however.
Correct, I'm referring to "decorated" fonts. The actual process of assembling and rendering bitmap fonts was never really a chore.
Luggage: Ok, "seven times" was a bit of an exaggeration ;) We did port to seven languages, although the euro fonts all overlapped quite nicely.
I agree bitmapped fonts have the potential to look the best, it's just a cost thing to me. If ttfs look good enough and I can ship with them, I see that as a time and money saver. Not just now, but down the road if I ever decide to localize to Korean or something. Keep in mind also that my current project has quite a bit of text.
That said, I'm still open to bitmap fonts if they don't work out, and if I do I'll come back here and take it like a man ;)
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.