font engine

Started by
2 comments, last by untalkative_monkey 22 years, 3 months ago
I''m reading through TWGPG and good ol'' Andre says that GDI is very slow and that I should make my own font engine. So I think, how the hell would i do that? So with my limited experience, I make a little font engine that basically loads a .bmp file with text in it, puts it on a surface, and then extracts letters like cells, and blits them to the back buffer. It works fine, but its even slower than the GDI text... so I figure, I''ll go to Gamedev.net, and check the tutorial... but it just tells me how to do GDI. So now I''m asking all of you, how do you make a damn font engine? ...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...
Advertisement
I just wanna add that Andre said he''d make a font engine in Black Art of 3D GP too. Hopefully he''ll do it in TOTWGPG #2 (I bet it got delayed because of the DirectX 8 release.)


"1-2GB of virtual memory, that''s way more than i''ll ever need!" - Bill Gates
The Adventure: Quite possibly the game of the century!" - The Gaming Community
---------------------------------------------------------------------------------------"Advances are made by answering questions. Discoveries are made by questioning answers." - Bernhard HaischReactOS
quote:Original post by untalkative_monkey
basically loads a .bmp file with text in it, puts it on a surface, and then extracts letters like cells, and blits them to the back buffer. It works fine, but its even slower than the GDI text...


You must be doing something really wrong. You basically do what you do. Here is how I do it:

1. load a bmp to a surface. The bmp has tha ascii charcter set of 256 slots

2. Based on the size of each charcter I generate an array with rects. This array consists of 256 rects.

3. I send the fontengine the x,y where the character should be blit. The destination surface and the string that should be blit.

4. The fontengine goes into a loop with one iteration per character on the string. (while szWord!=''\0'')

5. I take a character cLetter and calls the blitfast function.

6. The call to the blitfast function has only one interesting part and that is the source rect: CharacterRect[cLetter].

The trick is to use the fact that a space '' '' as a character actually turns out to be rect number 32 in the array (look at the ascii chart), or an ''A'' is 65 or something. Since you setup the array before the actual program started the array only needs the number to get the correct rect.

Hope this was of any use for you.



I am actually a Swede, living in paradise.
Why make it simple when you can make it sooo nice and complicated?
thats pretty much what i did! however, i didn''t set up an array of rects... i just made it calculate where on the surface it would be, for every single letter... i guess all the calculations were slowing it down a lot more than a rect lookup would huh? ok thanks i''ll try again!

...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...

This topic is closed to new replies.

Advertisement