Text output and Fonts

posted in OMG NUB! for project Gorgon
Published April 17, 2012
Advertisement
sitelogo.pngSweet merciful fark. That was painful.
I just spent the last 4 evenings/nights writing Gorgon's font system and it was not fun. And, of course, I'm still nowhere near done (still have to create the TextSprite object, and other the font effects like gradients and GDI+ image brushes). But, I got it working. Not only that, unlike the previous incarnation, it actually implements kerning properly (well, approximated kerning, I'm not dicking around with actual kerning. fark that.) One of the things about the 1.x font/text rendering that I absolutely hated was while it was worked, every now and again (especially on smaller fonts), it'd screw up and a letter would appear slightly (or not so slightly) shifted. Quite annoying. Here's a screen shot showing how awful it was compared to GDI+ and how awesome v2 is going to be (click to expand it):
GorgonText-300x118.png
Gorgon/GDI+ text comparison
Note that all text is the same font: Arial, 9.0 point, Bolded and Antialiased. Also note that v2.0 is nearly (but not quite pixel perfect) identical to the GDI+ DrawString version. I think that's a slight improvement.
After our forum member, ravl, had issues with Gorgon's fonts and DPI on his game, I decided to rethink how fonts are handled in Gorgon. Currently, the fonts are generated on the fly by copying the glyphs from a GDI+ font object (via DrawString) to a GDI+ bitmap and arranged on that bitmap to use the space as effectively as possible. Then that bitmap is copied to a Texture (or textures) and then the TextSprite uses those textures to draw the glyphs. This is all well and good, however, if the DPI is different on someone elses monitor, the font that's created on your monitor may be smaller/larger than the font when it's displayed on someone elses monitor. That's annoying. And, because I thought "Hey, no one will ever need to load/save these fonts because you can generate them on the fly!", you can't, well, save or load these fonts as bitmap fonts.
Enter Gorgon v2 fonts. These font objects will now be able to be persisted as-is as bitmap fonts. No more worrying about DPI, if it's 24 pixels high on your monitor, it'll be 24 pixels high on theirs. Gorgon v1 originally did fonts this way, but I had issues with kerning that I could never quite get past (until now), so I dropped it in favor of this scheme. It works well enough, except when it doesn't (see image above). However, what if you do care about font scaling? Well, no worries, I got that covered too. Gorgon will allow you to create these fonts in code like you could before.
I decided to forego putting the font object in the 2D library. I didn't want to tie it to the 2D stuff because really it's all just texturing and crap and no real geometry. So, it resides in the main graphics library as part of the textures object group (after all, it is essentially a very specialized texture). However, the TextSprite will be part of the 2D library.
My plans are to make the font completely customizable, and to that effect, custom glyphs can be added with custom textures. So if you wanted a giant flaming skull in the shape of an 'A' or some shit, you can do that and still keep your regular font. Kerning is customizable as is glyph advancement as well. I'm also going to make an editor for fonts so that building a font won't be a chore. But that's in the future.
Anyway. It's progress.

Source
Previous Entry Yet more shaders
Next Entry Gorgon v1.x
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Gorgon 3.2

10186 views

Gorgon v3.1.46.255

3384 views

Gorgon v3.1.45.248

3007 views

Gorgon v3.1.29.243

4296 views

Gorgon v3.1

4120 views

Gorgon Update #10

3020 views

Gorgon Update #9

3219 views

Gorgon Update #8

2962 views

Gorgon Update #7

3186 views

v3.0 Release

3741 views
Advertisement