• Advertisement

Archived

This topic is now archived and is closed to further replies.

How to render nice-looking typefaces in games?

This topic is 5104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello We''re just about finished with our game, and we''re pretty happy with it so far (in fact, you can download a beta at http://www.gamesresearch.com/hikari), and we''ll be releasing it soon. However, the typefaces could use some improvement. The situation is, we''re plotting a textured quad onto the screen for each letter. We''re doing this so that we can have more dramatic-looking typeface letters (e.g. gradiated, embossed etc.). The problem is that non-fixed-width typefaces render on the screen really poorly. Take lowercase i, followed by a lowercase j, for example. For a non-fixed-width typeface, the "correct" rendering of ij is to have the bottom of the j underhang directly beneath the i. Instead, there is a big gap between the i and the j, because the font renderer naturally starts rendering the textured quad for j past the end of the i. I''ve thought about some solutions, but what I''m really looking for is a robust, time-proven way of handling this, without using, for example, built-in typeface classes. Can I hear what people have to say about this? Is there a good resource out there that treats this topic rigorously? Thanks, -ss-

Share this post


Link to post
Share on other sites
Advertisement
Yes, I hear it''s much better in DirectX 9.0, but there are a couple of problems:

1) In the future, I want to target different platforms on which DirectX is not available.
2) More to the point, D3DXFont doesn''t support things like shading, animation, independent translation out of the box.

So you can see that, probably, D3DXFont is not the best tool for me to use. Nevertheless, thank you for your informative answer!

Share this post


Link to post
Share on other sites
is the problem with vertical or horizontal allignement?

if its horizontal, are you assuming that each character is the same width for rendering?

and if so, there must be some way to determine what the width of each individual character is, and then start drawing the next character offset by the width of the previous character.

Share this post


Link to post
Share on other sites
Stupid thing erased my message, so for the second time.

If you are using a standard windows font, then windows has some API commands that get the dimensions of the characters, use this to set the offset from one char to the next.

Or if you make your own fonts create your font class to contain this information so you know where to offset the next char based on a char by char width

Share this post


Link to post
Share on other sites
There are free programs that will create a bitmap from TrueType fonts and many of them will save extra information about each character, such as horizontal/vertical alignment, in a separate file that you can read in to your program. One program is located here and I think was written by a GDnet member (can''t remember who!). There are quite a few others out there as well.

Share this post


Link to post
Share on other sites
Then subclass D3DXFont... you can use your own bitmap for the letters.

Platforms that don''t support DirectX are irrelevent.

quote:
Original post by SilentSalamander
Yes, I hear it''s much better in DirectX 9.0, but there are a couple of problems:

1) In the future, I want to target different platforms on which DirectX is not available.
2) More to the point, D3DXFont doesn''t support things like shading, animation, independent translation out of the box.

So you can see that, probably, D3DXFont is not the best tool for me to use. Nevertheless, thank you for your informative answer!



Share this post


Link to post
Share on other sites
SelethD solution is pretty much the best you can do right now. Or maybe somebody else have done it, so try google won''t hurt.

Share this post


Link to post
Share on other sites
In the DX9 SDK there''s a text demo which dynamically loads a true type font and makes it''s corresponding quad set. It uses a list of positions for each letter so non-squared type faces are rendered properly, you can use that code as a base and use negative start offsets for letters that should "overlap" with the previous one.

The code is not DirectX specific, I easily ported it to an OpenGL based renderer.

Share this post


Link to post
Share on other sites
*marks aldisd as down as MS brainwashing victim number 294,838,935*
I wouldnt call the PS2 irrelevent, given that in the UK it had the highest number of game sales last year (nearlt 8million more than the PC at 18.29 million, where as the lovely DXable XBox only sold 3.96million...)

now, back to the topic at hand..
Just to thrown another idea into the ring, instead of doing a quad per letter why not do the whole word/sentance/whatever in one texture and then play with that? you could still do the effects you wanted and it might play better with the texture cache (although thats speculation).

or you could use the method that microserf outlined above with it...

As for how to do it, try googling for the FreeType library, I know it works with OpenGL and I'd be surprised if it didnt work with D3D



[edited by - _the_phantom_ on March 4, 2004 12:43:50 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by _the_phantom_
you could still do the effects you wanted and it might play better with the texture cache (although thats speculation).

As for how to do it, try googling for the FreeType library, I know it works with OpenGL and I''d be surprised if it didnt work with D3D


If all characters in your font are stored in the same texture, why would this matter? It seems to me that your method would not really be suitable for dynamic text. How would you create the textured quad with all the letters in the sentence every time the text changes? GDI? FreeType? I supposed you could render to a texture and then onto your sentence quad but this would still imply that you had a way of texturing a single character. The main benefit I see is that you lowered the triangle count from 2 per character to 2 per text block.

You can use FreeType with DirectX just fine and the quality of the fonts looks better than GDI anyways. Their website also has a great tutorial on the theory of how fonts work.

Share this post


Link to post
Share on other sites
yeah, good point, thats what i get for making posts when i''m tired
As for using a quad vs multiple quads, it depends on how often the text is changed as to what is better i surpose, if the text is constructed once and never really changed i might be better to build it into one texture and leave it, same with if its not updated ''very often''
I''ll admit i''m as yet to try the above idea, but it seems relatively fessable to me.

and all of the above is based on the idea of using freetype as he mentioned wanting to consider crossplatform at a later date thus using the GDI doesnt seem like a sane method.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Freetype is not the answer if you want to deal with true-color font printing. Freetype is a great open-source rasterizer for TrueType and Type 1 fonts; however, both of those font systems are black & white. The fonts merely specify outlines. This doesn''t sound like the solution you''re looking for.

Your only issue right now is kerning. The standard way of dealing with this is through a table of kerning pairs. I''m a bit surprised that kerning has not been mentioned in the 12 replies so far.

You probably should read up a little on some of the theory and the file formats. For what you need, you really don''t have to go beyond kerning, but it can''t hurt to know more. Here''s some references:

http://www.microsoft.com/typography/default.mspx
http://developer.apple.com/fonts/
http://partners.adobe.com/asn/tech/type/index.jsp

I''m guessing that whatever fonts you''re using, even though they''re true color, you probably started by just laying down all the characters from either a TrueType or a Type 1 font. Either way, you can write a program quickly to extract the kerning tables. If you''re going to use their kerning tables, be sure to use their character width information, too. The specs for TrueType and Type1 fonts are no more than a couple of clicks away from any of the pages listed.

Share this post


Link to post
Share on other sites

  • Advertisement