1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
VOID WriteText(LPCWSTR text, RECT extent)
{
SIZE size = {0};
TEXTMETRIC tm = {0};
HDC hdc = wglGetCurrentDC();
GetTextMetrics(hdc, &tm);
int cx = extent.left;
int cy = extent.top;
size_t len = wcslen(text);
size_t start = 0;
size_t i = 0;
for (; i < len; i++)
{
if (L' ' == *(text+i))
{
// get width & height of next word
GetTextExtentPoint32(hdc, text + start, i - start, &size);
if (size.cx > (extent.right - extent.left))
return;
// new line
if ((cx + size.cx) > extent.right)
{
cx = extent.left;
cy += tm.tmHeight;
if ((cy + tm.tmHeight) > extent.bottom)
return;
//start += 1;
}
WriteText(text + start, cx, cy, i - start);
start = i;
cx += size.cx;
}
}
WriteText(text + start, cx, cy, i - start);
}
VOID WriteText(LPCWSTR text, INT x, INT y, INT len)
{
if (0 == FontBase || NULL == text)
return;
glDisable(GL_TEXTURE_2D);
glColor4f(FontColor[0], FontColor[1], FontColor[2], FontColor[3]);
GLfloat pos[] = { (float)x, (float)y, 1.0f };
glRasterPos3fv(pos);
glPushAttrib(GL_LIST_BIT);
glListBase(FontBase - 32);
glCallLists(len, GL_UNSIGNED_SHORT, text);
glPopAttrib();
}
|