🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

About true type fonts

Started by
7 comments, last by BennyJensen 24 years, 5 months ago
There must be some way to use .ttf fonts on a directx surface without GetDC() ??? Using GetDC and then DrawText or TextOut is really slow, but creating your own routines/ fonts to write text is too much work I remember doing that stuff on my A500 in the old days when coding demos. Anyway, I noticed that Diablo shipped with 2 .ttf fonts (inside the mpq file ofcourse). So, I wonder how they used these fonts to write text on the playing surface. Also, they used these fonts without adding them to the windows font list. Anyone know how they did this? - Benny Jensen
Advertisement
you can load in a font from a ttf, and write each letter onto a surface using GetDC. then you have all of the letters on the surface, and you no longer have to use GDI.

Get off my lawn!

TANSTAAFL,

I am currently doing that with an external program and save the surface to disk as a BMP. I always have to load the TTF into the font directory by hand. Is there a way I can read the TTF file from disk during program execution? If so, what is it?
Well, I will still have to make my own routines for using
the "new" font I''ve created. And that was something I
hoped to avoid
But if I have to, I''ll do it. But I still need info about
the size of each letter (Fixed width fonts sucks).
Does DrawText or TextOut return any info about this?

-Benny Jensen
Btw: Is it possible to read in a .ttf font from disk and use it? Without adding it the window font list that is?

-Benny Jensen
or if it''s a smaller game, you can write the stuff you need to write onto a bitmap.
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
BennyJensen,

Take a look at the function GetTextMetrics. It returns a structure with a lot of information about the font currently selected into a device context. GetCharWidth will return the width of one character, and I beleive you can use the GetTextMetric''s height for all your characters. Then you just need to make a structure that contains those widths. I would store each image in a bitmap with the same spacing (maximumum character size) so that you can use just one rectangle for blitting, offset by your character''s index into the array. Then, between letters, advance by the character''s width (stored in the array).
Check out the allegro homepage at:
http://www.talula.demon.co.uk/allegro/

Look for a program called ttf2pcx. It comes with complete source. You might be able to pick something up from it.
Ok, understanding there was no easy way, I had to create a program that stores each letter as a set of x,y coords.
I drew each letter to a surface, and then checked the surface pixel for pixel to generate the coords.

So, when I use the new font, I have to draw each letter pixel by pixel. I guess this is pretty slow, but at least I can draw text in any color this way.

Anyway, thanks for the help.. I didn''t use GetTextMetrics, but some Get...Point32 function to get the width of each char. (I dont remember the excact name of it)

This topic is closed to new replies.

Advertisement