• Advertisement
Sign in to follow this  

Using text in DirectDraw

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

Hey all, Someone gave me a nice function to output text, and I have made my own function on that one: void DrawTextColor(int xout, int yout, const char *txout, int r, int g, int b) { if (g_pDDSBack->GetDC(&hdc) == DD_OK) { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, RGB(r,g,b)); TextOut(hdc, xout, yout, txout, strlen(txout)); g_pDDSBack->ReleaseDC(hdc); }; } My next question is, how to set a Font ? I've looked into the MSDN library here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_9r77.asp , But I can't find anything... :( Do I need to set a font, or do I need to stretch something out ?? Greetz, Padschild

Share this post


Link to post
Share on other sites
Advertisement
Hi, this snippet should get you going. Search MSDN for additional info.
Good luckies.


HDC hdc;
HFONT hOldFont;

HFONT font = CreateFont(12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FIXED_PITCH|FF_DONTCARE, "verdana");

Surfaces->BackBuffer->Surface->GetDC(&hdc);
hOldFont = (HFONT)SelectObject(hdc, font);
SetTextColor(hdc, pColor);
SetBkMode(hdc, TRANSPARENT);

TextOut(hdc, x, y, pMsgTxt, strlen(pMsgTxt));

DeleteObject(font);
SelectObject(hdc, hOldFont);
Surfaces->BackBuffer->Surface->ReleaseDC(hdc);

Share this post


Link to post
Share on other sites
Just to clarify, you only want to create your font once. Do that in your initialization code. Then when you want to use it, call SelectObject passing your HFONT. After drawing your text, pass the old HFONT to SelectObject to reset it. Also, don't destroy the font until your done with it. Do that in your shutdown code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement