-
Notifications
You must be signed in to change notification settings - Fork 0
/
font.cpp
49 lines (42 loc) · 1.2 KB
/
font.cpp
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
#include "font.h"
Font::Font(HDC hDC, int iSize, LPCTSTR sFontName)
{
iBase = glGenLists(96);
hFont = CreateFont( -iSize,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH,
sFontName);
HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
wglUseFontBitmaps(hDC, 32, 96, iBase);
SelectObject(hDC, hOldFont);
DeleteObject(hFont);
}
void Font::Print(float x, float y, const char *fmt, ...)
{
char text[256];
va_list ap;
if (fmt == NULL)
return;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);
glRasterPos2f(x, y);
glPushAttrib(GL_LIST_BIT);
glListBase(iBase - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
Font::~Font()
{
glDeleteLists(iBase, 96);
}