Archived

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

How do you display text with YOUR font engine?

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

Before i program anything i like to know the principle, not necessarily how to do it. Todays question is: Do you render the letters in your font engine by using the normal windows text, of do you have a bitmap for every letter and then render the appropriate bitmap to form a sentence. regards ace

Share this post


Link to post
Share on other sites
so is it a case of having a bitmap letter for every character hand drawn or whatever, then u manually managing the location ofthe characters that are to be written. So depending on the key the user presses, a switch statement of whatever is used to determin which character to draw to the screen.

??
regards

ace

Share this post


Link to post
Share on other sites
No. Ew. You use the value for the key that was pressed, and use that to index into a bitmap array. For example, since ''B'' is one higher than ''A'', it would be the next graphic in the bitmap, and you could just use the actual number instead of a switch statement to tell which letter to draw.

I have a bitmap containing an image of every letter, then I draw quads with texture coordinates set to only show that letter. The bitmap is drawn using Win32 GDI functions, so I can have pretty ClearType antialiased fonts in my game.

There are a lot of different ways to do things, you should pick up a couple of the tutorials out there, and look at SDK samples to see how you could do this; in the end, it''s essentially a matter of style preference.

Share this post


Link to post
Share on other sites
ID3DXFont->DrawText [for the directx version, which for now is the only version]



Basically it takes a string, so I just let windows do all of the font work and just pass simple C-style strings and which font to use to it. The actual string can come from a variety of places, but that's not rendering.

Share this post


Link to post
Share on other sites
Quote:
Original post by fyhuang

I thought that the DX DrawText() was slow (used polygons instead of textured quads)? Or maybe I'm 'behind the times'...




Damned if I know.



What's the old expression? "Make it work, then make it fast."



Share this post


Link to post
Share on other sites
We have an engine which supports unicode... Since it's pretty
bad to just reserve place for all 65k unicode characters
you have to be a bit more inventive :)

We have a little algorith which nicely fills rectangles
(hey no need to reserve 32x32 pixels for a '.' just
because the biggest letter appears to be 32x32 pixels).
For an example of such an algo, look for 'blackpawn'
there is a tutorial on sth like that.

Then we take a truetype font, based on optimal position
render it into a directX texture (obviously check first
if we already have it cached in this texture first)
and then render the characters.

The render function get a parameter rectangle, extra
options include 'align center/vertical/left/right'
and 'autonewline', break if text>maxPixWidth and so
on.

Regards
Roger

Share this post


Link to post
Share on other sites
I use windows fonts (D3DX), because that way I can use any font installed on the computer. If I need a custom font, I can install it to the user's system.

D3DX font functions just fill a dynamic vertex buffer (using D3DXSprite) for rendering.

Quote:

I thought that the DX DrawText() was slow (used polygons instead of textured quads)? Or maybe I'm 'behind the times'...


What? A "textured quad" IS a polygon.

D3DXFonts are not slow by any stretch of the imagination. It is extremely unlikely that you will be able to write a faster method of doing so (you can probably accomplish the exact same thing, of course, but that'd be pretty pointless :-p).

Share this post


Link to post
Share on other sites
I have a custom made stream class (the streaming is delegated to a stringstream) that supports variable width fonts, various alignments, positioning, and changing the current color mid-stream. A font consists of an image containing all of the characters and a small file listing the widths of all the characters. A single character is drawn using texture mapping.

Share this post


Link to post
Share on other sites
With SDL I wrote support for both truetype fonts and bitmap fonts (created with the Bitmap Font Builder) by following easy tutorials.
I'll probably use bitmap fonts only for the projects I start now.

I want to write a new filetype that can be used as tileset or for saving animations AND for bitmap fonts.
Not sure if I can do it though. But that is what I want to do in theory.
A file would probably hold several images and all the images different layers as sub-chunks.
So a font would hold all the letters/characters in its layers.
The font engine would have to know what to expect from the font resources of course.

Probably I'm dreaming though ...

Share this post


Link to post
Share on other sites