Using text in DirectDraw
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
Hi, this snippet should get you going. Search MSDN for additional info.
Good luckies.
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);
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement