🎉 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!

Font Engine

Started by
1 comment, last by Piccolo 24 years, 6 months ago
OK. I made a function that takes a font name, width, height, etc. as parameters. Then the function will extract all the bitmaps for the font(has to be truetype). My question is how would i write the data structure and drawing function? I already have the function that loads the font in and extracts the bitmap.
Advertisement
I''m assuming your using Direct Draw, but if not, this should apply to DC''s just as well.

First of all, to avoid retarded, unnessisary overhead I would make one big suface (or DC) that is large enough to hold all your images. So if you have 256 characters (probably will have less) and your height/width is 32/32 then I would make the surface 32/8192 (256 * 32) Then I would load the font images into this suface in order of their ASCII value, then you could draw a character just by blitting the rect that has a top of 0, bottom of 32, left of 32 * (value of the character), and right of 32 + left. this should work great, and quick. All you have to do is pass the funtion a null terminated string, and then do this 1/2 pseudo code.

void DrawString(char * string)
{

//this funtion assumes the height and width are 32/32
//you can add variables to change this if you wanna

RECT bltrect;
bltrect.top = 0;
bltrect.bottom = 32; //check this, it may need to be 31

while (string != NULL)
{
bltrect.left = 32 * string;
bltrect.right = bltrect.left + 32;
BltRectFromFontSurface(&bltrect,DestSurfacePointer);
}
}


That should do it for ya, if not, email me at Pseudo_me@email.com

Pseudo
OK. I got it to work but there is a problem...it doesnt draw text it draws a colored specrum...very strange. So i changed my strategie and told GDI to draw to a off-screen surface but i got the same problem...strange again. Anyhow i think i will just use my own buffer and draw to it...i will loose some speed but oh well...

This topic is closed to new replies.

Advertisement