Jump to content
  • Advertisement

Archived

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

JIMbond21

Putting text in a window

This topic is 5622 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 know how do display text using DrawText() and how to make fonts and such, but I want to know if there is a way to draw text to an hdc in memory then display that to the window later, say for double buffering in a game. THX, JAP

Share this post


Link to post
Share on other sites
Advertisement
Just make a memory dc large enough to hold the text, and use DrawText or ExTextOut to draw to the memory dc, then later on, to display that text, Blit the memory dc to the backbuffer before you flip it. On a side note, I use ExTextOut because it is a little faster, but it also doesn''t do wordwrap and some other things DrawText does.

Share this post


Link to post
Share on other sites
How do I make this memory dc large enough for text, would this work,

HDC hdcMem = CreateCompatibleDC(hdc);

or is there another way to make it, because nothing displays when I use the memory dc method. This is the current function I have,

void drawtext( HDC hdc, RECT* prc )
{
HFONT hf;
HDC hdcMem = CreateCompatibleDC(hdc);
FillRect(hdcMem, prc, (HBRUSH)GetStockObject(WHITE_BRUSH));
HDC hdc2;
long lfHeight;

hdc2 = GetDC(NULL);
lfHeight = -MulDiv(100, GetDeviceCaps(hdc2, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc2);

hf = CreateFont(lfHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");

char szSize[] = "See Christmas";
HFONT hfOld = (HFONT)SelectObject(hdcMem, hf);

SetBkColor(hdcMem, RGB(255,255,255));
SetTextColor(hdcMem, RGB(255,0,0));
SetBkMode(hdcMem, TRANSPARENT);

DrawText(hdcMem, szSize, -1, prc, DT_SINGLELINE);

BitBlt(hdc, 0, 0, 100, 100, hdcMem, 0, 0, SRCCOPY);

SelectObject(hdcMem, hfOld);
DeleteObject(hf);

}


THX,
JAP

Share this post


Link to post
Share on other sites
When you create a memory DC, if I recall correctly, the default bitmap is 1x1 and monochrome. You''ll need to create a bitmap of large enough size and bit depth and then select that into your memory DC before you draw to it.



Qui fut tout, et qui ne fut rien
Invader''s Realm

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!