Jump to content
  • Advertisement


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


A simple textout problem? - my code inside

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

The problem I am having is: This is a directdraw game, in which you have a book you can read. Depending on the page of the book you are reading, this function uses TextOut to paint different text over the already drawn page. It uses 3 different fonts to display the information, (a bold title font, a small postscript font, and a middle font for the rest) almost always making use of the three fonts on every page that could be displayed. Now the problem is, in the game, we turn to a page, and the text is displayed fine. Three different size fonts are displayed, just as intended. But if we leave the same page displayed for a while (about 10 - 15 seconds) the text all reverts to the largest font (called boldfont in the code, and created last of the three fonts by the program). All of it, even the text which is supposed to appear smallest. As i say, the first time we view the text it appears perfectly, but leave it displayed for 10 to 15 secodns, and it becomes very large. Here is the function which draws the text. It is called every frame by the game. - CODE STARTS HERE - int a = 175 * position; char strPrintFontName[32] = "arial"; char FontName[32] = "arial bold"; char smallname[32] = "book antiqua"; LOGFONT lf; lf.lfHeight =-10; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = 500; lf.lfItalic = FALSE; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = ANSI_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN; lstrcpyn( lf.lfFaceName, (const char*)strPrintFontName, LF_FACESIZE ); HFONT font, boldfont, smallfont; font = CreateFontIndirect (&lf); lf.lfHeight = -9; lf.lfWeight = 400; lstrcpyn (lf.lfFaceName, (const char*)smallname, LF_FACESIZE); smallfont = CreateFontIndirect (&lf); lf.lfHeight = -16; lf.lfWeight = 600; lstrcpyn( lf.lfFaceName, (const char*)FontName, LF_FACESIZE ); boldfont = CreateFontIndirect (&lf); HDC hdc; G.lpDDSBack->GetDC(&hdc); SelectObject(hdc, boldfont); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(0, 0, 0)); TextOut (hdc, 54 + a, 85, "Title", 5); TextOut (hdc, 54 + a, 98, "Here", 4); SelectObject (hdc, smallfont); TextOut (hdc, 120 + a, 84, "-a small font-", 14); TextOut (hdc, 120 + a, 92, "-for our subtext-", 17); SelectObject (hdc, font); TextOut (hdc, 53 + a, 115, "A whole load of text here", 25); TextOut (hdc, 53 + a, 125, "this is the main font", 21); TextOut (hdc, 53 + a, 135, "prints what", 11); TextOut (hdc, 53 + a, 150, "this particular page", 19); TextOut (hdc, 53 + a, 160, "should contain", 14); DeleteObject (boldfont); DeleteObject (font); DeleteObject (smallfont); G.lpDDSBack->ReleaseDC(hdc); - CODE ENDS - forget the a in the positioning part of TextOut, it is a simple posiotioning sum. The problem occured before I added it. So the function builds a typical LOGFONT, and creates a font using the LOGFONT's details. Then we change a couple of the LOGFONT's details and create a new smaller font with those details. Then we do the same for a bolder and taller title font. Then we create and select our HDC, select our background mode and textcolour, we have selected our current font, and then print text. Over the course of printing all the relevant text, we use all 3 fonts, using SelectObject. At the end of the function we DeleteObject our fonts, to free up the space they were taking up. (of course we create them again when the function is next called, which is the next frame if the book is still open.) So that is my problem. Any idea why it is happening? I can't figure it out. I think I have to call the Delete Object each time the function is called, otherwise there would be a memory problem (I think). Anyway, I appreciate any input upon my problem. Thanks anyone who takes the time to reply with suggestions and other comments. Edited by - Leggyguy on October 19, 2001 2:08:30 PM

Share this post

Link to post
Share on other sites

You do NOT have to call DeleteObject() after the drawing of only one frame, just create the font objects at the program start and delete them with DeleteObject() when your program ends -- this will speed things up a lot also!

I have no idea why after 10-15 seconds everything is switched back to bold font. Maybe creating and deleting the font objects at the program start / end solves it, but, if it does not, you should try to find out what happens before 10-15 seconds, and what happens after that. What´s the major change which is causing the all the text to become printed in bold font?

Good luck


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!