Jump to content
  • Advertisement


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


Font Engine - Need assistance pls!

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

I''ve been using GDI for displaying in-game information and statistics for some time, but as it''s painfully slow I think it''s about time to make a font engine myself... Haven''t been doing any coding as of yet, only some very basic planning... What I have in mind is using an offscreen surface holding a-z and 0-9 characters, and having a function looping through the string blitting the characters one after another using DirectX... I don''t have a problem with normal text strings, but when it comes to displaying score and such I have no idea how to make it happen... Yet! In a text string i can just use "Switch (Current_Character), Case ´a´: Source_Cords_To_Blit_From = xy_Values_For_A_In_Bitmap and so on... Is it possible to loop through int stored values the same way as char[] strings? Any other better approach to determine which digit in turn? I think I''ve seen some Windows function calls somewhere combining text and numerals, can''t remember where though... Thanks in advance!

Share this post

Link to post
Share on other sites
Just create one string containing the complete output character list and draw that.

Either use a CStream in C++, or write a printf()-like function in C, this is fairly easy:
void MyPrintf(LPDIRECTDRAWSURFACE7 p_pDDSurface,
int p_nX, int p_nY, char *p_pszText, ...) {
char l_pszText[1024];
va_list l_CList;
int l_nPos;
char l_nChar;

// Expand the format string

va_start(l_CList, p_pszText);
vsprintf(l_pszText, p_pszText, l_CList);

l_nPos = 0;
while(l_nChar = l_pszText[l_nPos++]) {
// Blit l_nChar at p_nX, p_nY
// increase p_nX by char''s width



If you, say, call the function like this
MyPrintf(lpDD, 10, 10, "Player: %s | Score: %i", pszPlayerName, nScore);
Inside the function, l_pszText will read "Player: Me | Score 123" - you''ve got a single string containing all the text and numbers in order.

There''s also sprintf() which is like printf(), it just prints into a string instead to the screen (stdout). And there are conversion functions like itoa() atoi() (int to asciiz, asciiz to int) ftoa() ultoa(), etc.


Share this post

Link to post
Share on other sites
vsprintf?! Argh..I wish I hadn''t come across this thread! Some time ago I wrote my own version of that very function, not knowing there already was one! *sigh* It even supported most of the format specifiers that vsprintf does and some new too..like %b for binary output hehe. Anyways, seeing that there''s a function to do the same job as mine I think I''ll have to go change it..even though mine was a bit faster with medium and long "formatings" .

Until later..I''m off to bang my head against the wall and erase two hundred lines of code .

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!