Problems with font engine.

Started by
4 comments, last by VisualLR 23 years, 12 months ago
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


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
mhanna@nyc.rr.com
Yea, Im using DirectX, but can you use custom fonts like that? the main reason Im using this approach is so I can use custom fonts with different colors and some with texture too.

later!



Luis Sempe
visual@guate.net
http://www.geocities.com/SiliconValley/6276


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.











codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"
id=amorano footer width=360 height=140 border="0">







When Quality Matters



Send all mail to amorano@bworks.com


Joviex, great idea, I''ll do that today.

Thanks!



Luis Sempe
visual@guate.net
http://www.geocities.com/SiliconValley/6276


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
[email=jperegrine@customcall.com]ColdfireV[/email]

This topic is closed to new replies.

Advertisement