Jump to content
  • Advertisement

Archived

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

VisualLR

Problems with font engine.

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

Hi, Ive been writing a font engine to use with my game, the approach that I took was to have the font in a bitmap and load it from there and then blit the letters from there, the problem I have is with drawing the fonts correctly on screen, how do I calculate how separate each character has to be? and how is the position of the lower case letters such as "p, y, g and q" that are supposed to be drawn a bit lower than the other characters calculated so it looks correct, Ive tried using different values, but if the font size changes then I get incorrect results. Thanks! Luis Sempe
visual@guate.net
http://www.geocities.com/SiliconValley/6276


Share this post


Link to post
Share on other sites
Advertisement
If you''re using DirectX, you can write the letters to a surface using TextOut (since you only need to this once at the start of your app, the speed isn''t too important).

Then all you need to do is blt from your font surface to the backbuffer...just store the width of each character in an array indexed by the ASCII code of the character. To get the width of each character you can call the Win32 function GetTextExtentPoint32 (see msdn.microsoft.com/library) for each character. If you''re using DirectX let me know and I''ll post some code.

Hope that helps :-)


mhanna@nyc.rr.com

Share this post


Link to post
Share on other sites
quote:
Original post by Gamera

If you''re using DirectX, you can write the letters to a surface using TextOut (since you only need to this once at the start of your app, the speed isn''t too important).



If you want to know the exact way to put the fonts, I would do it the above mentioned way and take a snapshot of the surface (save as a bitmap). Then open it up and take a look how it was spaced, and derrive some calculations from there.












Share this post


Link to post
Share on other sites
Here''s an easier way. Just open up MS Paint and select the font tool. Select a fixed-width font (like Courier-New), and type in "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" and whatever else letters you want. Save the bitmap, and calculations will be a helluva lot easier. Then I''d do this. Create an int array with 256 spaces. Then write some function that fills in the array with the offset on the bitmap to each letter. For example, I think the capital letter ''A'' has an ascii value of 96. And let''s say the letter is the 27th spot on the bitmap, because you put lower case letters in there first. And just because, we''ll say the letters are 6 pixels wide in the bitmap. So the capital A will be at pixel ((27 - 1) * 6) = 156. The function that you write will assign FontArray[96] = 156; Or better yet, it should say FontArray[''A''] = 156; And FontArray[''B''] = 162; Get it? Then, to figure out what the x-offset on the bitmap is for any letter, you just look it up in FontArray[letter]. Cool, huh? But you have to do it your own way, with each letter being so many pixels wide, which letters are in the bitmap, which order the letters in the bitmap are, etc. Good luck!

E-mail me if you didn''t fully understand that.



ColdfireV

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!