Skip to main content
gamedev.net
🔒 Locked

Making a font engine

Started by BradDaBug 2 replies 200+ views
Original Post
BradDaBug
BradDaBug
I have writting this thing so many times I can''t believe I still can''t remember how to do it. What I''m trying to do is make a font engine that takes the ASCII code of a character and matches that to a bitmap containing the character set and then blitting the proper letter or number onto the screen. The bitmap is set up in a 16 X 16 grid of characters. Heres the code I''m trying to use: for (unsigned int count = 0;count < strlen(text); count++) { SourceRect.left = text[count] & 15 * 15; SourceRect.top = text[count] / 15 * 11; SourceRect.right = SourceRect.left + 15; SourceRect.bottom = SourceRect.top + 11; if FAILED(hr = Display->Blt(x + count * 10, y,FontSurface,&SourceRect)) WriteLog("Could not blit! Error: %d",hr); } "text" contains the string I''m trying to blit. I''m also using the DDUtil.cpp stuff...not straight DirectDraw. Each letter is about 15 X 11. When I use this code i just get jibberish instead of the right text. What''s wrong?!
I like the DARK layout!
Colin Jeanne
Colin Jeanne
The x position of the character on the font surface will be:

text[count] % number_of_characters_wide

This is because your font surface has x number of tiles wide and you want a number between 0 and x-1 which is what modulus will give you.

The y position of the character on the font surface will be:

text[count] / number_of_characters_wide

This is because you are trying to find which row you are on in the font surface. If your surface is 5 characters wide and you want to blit character 13 then you know you would be on row 2 because 13/5 is a little more than 2 and you round down the extra stuff.

Remember, these are only the positions in character tiles. You will still need to create the rect to use for the blit.

Invader X
Invader''s Realm
Big Sassy
Big Sassy
And you probably should store the length of text rather than getting it with each loop. ex:

int length;

length = strlen(text);

for(unsinged int count = 0; count < length; count++)
{
//blah blah blah

You would save yourself some time. Just a thought

EDIT - missed the t in thought. damn typos...

Edited by - Big Sassy on October 11, 2001 3:14:58 PM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.