Jump to content
  • Advertisement
Sign in to follow this  
sakky

Custom font with D3DX

This topic is 4565 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

Okay a, I don’t know where else to ask this, so I came here. I need to draw text in my game using font I created in a paint program (Photoshop, go figure). Basically, my needs are to use this font I created using the ID3DXSprite & ID3DXFont interfaces. The reason for those choices are because the DirectX SDK states that a ID3DXSprite interface should be used with the font IF many subsequent call are made to the font’s “DrawText” method. I will be calling this quite a lot in some cases where it may cause issued because I’m scrolling the text and also using adding glared or flares I should say. But my question is how I rig up the sprite and font interface to use the font I created and save to a bitmap. Should this be done, or am I barking up the wrong tree for this purpose?

Share this post


Link to post
Share on other sites
Advertisement
No takers huh? Well I found this Bitmap Font Builder program. I generated font using it and customized it a bit in Photoshop. So it’s pretty much the same thing at my other font.

The part that I don’t get is how this all works. I created a sprite and a texture. I also created a font with the same parameters as what’s on the bitmap. I start the batching (if that is what you call it) with ID3DXSprite::Begin( ), then I use the ID3DXFont::DrawText the number of times I need to. Then I end all the batching with the ID3DXSprite::End( ). And some how the font interface uses my sprite and texture map? I don’t see how this works, so I’m going to take for the minute it doesn’t.

I done something similar to all this before using a routine that generated the correct rectangle on a bitmap (This was in DirectDraw by the way) for a character. I had only a limited set of characters. Because I wanted to use a different set of colors I made the fonts with their different colors and simply used the function with a special flag the specified what type of color to use. I added an offset to the color with the flag that gave the correct location on the bitmap. Pretty cool, but also pretty lame because I only had Aa-Zz && 0-9, plus a few punctuation marks (i.e. “. ! ‘ _”).

I don’t want to do this again because it was so limiting. The font I want is in a 32-Bit TGA file. The alpha channel is the exact match of the font it’s self. The font has a little shading or glare applied to it via chrome gradient. It looks pretty nice and has all the characters (that I know of) that I should use.

So I must simple pre-compute the source rectangle again and use the sprite class for the rendering of the characters. I draw a string with formatted output via variable argument list and traverse the resulting string, rendering each character’s character via offset into the array by value. Something like " " - Char.

Share this post


Link to post
Share on other sites
I'd personally suggest you just go with a True Type font and avoid the bitmap fonts all together. Save some headaches, in my experience, there's about a billion free fonts on the net, and DX will load 'em right up for ya.

Share this post


Link to post
Share on other sites
Looking at the documentation of ID3DXFont and its factory functions, it doesn't support what you want.

Quote:
So I must simple pre-compute the source rectangle again and use the sprite class for the rendering of the characters. I draw a string with formatted output via variable argument list and traverse the resulting string, rendering each character’s character via offset into the array by value. Something like " " - Char.

Yep, you can do this. Don't use variable argument lists - do it the C++ way. Much safer.

Share this post


Link to post
Share on other sites
Quote:
Original post by Instruo
I'd personally suggest you just go with a True Type font and avoid the bitmap fonts all together. Save some headaches, in my experience, there's about a billion free fonts on the net, and DX will load 'em right up for ya.

Yea, I recommend this as well. Just search google for "free fonts", and browse through a bunch of the pages. Actually finding cool fonts isn't hard - but finding something that you are looking for is pretty tough. This is because the sites always store them alphabetically, and their names really give no indication of the font itself. But nonetheless, it is a good route to take.

Share this post


Link to post
Share on other sites
Make sure you read the licences that come with any free fonts...

I think it was somewhere on these forums (month or so back) that someone had built their entire game using a free font off the net, then checked the licence and found that it was for "personal use only" and you couldn't redistribute it in a commercial product [oh]

Jack

Share this post


Link to post
Share on other sites
You're definitely NOT wasting your time! Bitmapped fonts are a great option because you can do SO much with textured quads in D3D. I can post my font bitmap and measurement file if you are interested (I have two, actually). I get REALLY nice quality results, including a build in drop shadow (that you can eliminate by rendering with additive blending.) Plus you can scale/color/rotate/fade( <-important!) your text just like any other sprite/quad.

Quote:
Original post by Instruo
I'd personally suggest you just go with a True Type font and avoid the bitmap fonts all together. Save some headaches, in my experience, there's about a billion free fonts on the net, and DX will load 'em right up for ya.


I think this advice is misguided. Not only do you have to redistribute the font (which can be a headache) but the font must be rasterized at SOME point anyways. Video cards do not accept TTF files, they take vertex and texture data (etc... correct me if I'm wrong...) Plus the memory requirements are not large for modern cards. I spend a 512x512 PNG (w/ alpha, = 64x64 pixels per character, I use about 110 characters) and can scale up to roughly "70 point" size before you can see pixellation.

If you rasterize the font into a bitmap, you are free to redistribute your artwork with your game under most any font license, commercial or otherwise. As a bonus, you can only include the characters you care about, color them in complicated ways if you choose, and include extra characters (such as arrows, small scroll bar pieces, whatever fits) so that you can just add another instance of your 'label/text' class to show those symbols, as a convenience.

Edit: render with a dynamic vertex buffer (if you have effects like fading, rotating, etc.) or a static vertex buffer if the text isn't changing, and you'll get blazing speed using texture coordinates because you can render all the characters in one pass.

You can do all this by using your bitmap/texture with the Sprite interface as necessary, as well. Sorry if this doesn't directly answer your question!

Share this post


Link to post
Share on other sites
A finally some one agrees with me! So bitmap fonts it is. I knew they would be good because it’s a texture and not vector/spline related fonts to worry about. Besides, I see a lot of games include Quake use that type of font.

So any ways, yes Maters, gives us you fonts. (hehehe)

Is there a program or way to build them? I’m not talking about Bitmap font builder because it won’t let me choose the chars I want. Also, Photoshop (that I know of) doesn’t have a tool that will help me much. It’s little font thingy might help, but not much. I can never get the characters to space out right. I think this is because the font I would be using isn’t mono space.

So like, in Photoshop I KNOW I can make some cool fonts. Photoshop is all I have for graphics tools. But I need a way to measure the font and place the characters in their correct cells. But most importantly I need to be able to render them correctly.

Masters, how do you mean, use a vertex buffer? This would only work for mono space with out showing distortion via characters spacing out to much, would it? Also, I will be fading, scaling, rotating and all the like with the font. And I will most likely be drawing multiple lines. So ah… how did ya pull that off?

I want to use a 32-Bit TGA or BMP. In Photoshop, the TGA seams to hold the little glares and stuff I put in the font. I haven’t tried using BMP version yet. Actually, the characters that I rendered screwed all up. I had the source rectangles wrong and I gave up shortly after reading some of these posts until I seen yours and Hyena’s.

I’ll be doing lost of scene transitions and special effects with the text.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!