-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfont.cpp
More file actions
122 lines (101 loc) · 2.96 KB
/
Copy pathfont.cpp
File metadata and controls
122 lines (101 loc) · 2.96 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#define WIN32_MEAN_AND_LEAN
#define WIN32_EXTRA_LEAN
/*********************************************************************/
/** \file font.cpp
\brief The CFont class implementation */
#include "font.h"
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <gl/gl.h>
/*********************************************************************/
/** CFont class constructor
**********************************************************************/
CFont::CFont()
{
screenX = 0;
screenY = 0;
xpos = 0.0;
ypos = 0.0;
zpos = 0.0;
}
/*********************************************************************/
/** CFont class constructor
\param name Font name
\param size Font size
**********************************************************************/
CFont::CFont(char *name, int size)
{
screenX = 0;
screenY = 0;
xpos = 0.0;
ypos = 0.0;
zpos = 0.0;
Build(name, size);
}
/*********************************************************************/
/** CFont class destructor
**********************************************************************/
CFont::~CFont()
{
glDeleteLists(callList, 96);
}
/*********************************************************************/
/** Creates the font.
Characters are stored in a display list
**********************************************************************/
void CFont::Build(char *name, int size)
{
HFONT hFont; // font ID
HDC hDC; // device context
hDC = wglGetCurrentDC();
callList = glGenLists(96);
if (stricmp(name, "symbol") == 0)
{
hFont = CreateFont(-size, 0,0,0,FW_BOLD, FALSE, FALSE, FALSE, SYMBOL_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH, (LPCTSTR)name);
}
else
{
hFont = CreateFont(-size, 0,0,0,FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH, (LPCTSTR)name);
}
SelectObject(hDC, hFont);
wglUseFontBitmaps(hDC, 32, 96, callList);
}
/*********************************************************************/
/** Renders a string in the screen
\param str Text to be displayed
**********************************************************************/
void CFont::Print(const char *str, ...)
{
char text[256];
va_list args;
if (str == NULL)
return;
va_start(args, str);
vsprintf(text, str, args);
va_end(args);
glPushMatrix();
glColor4f(r, g, b, a);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -1.0f); // translate one unit into the screen
if (xpos == 0.0 && ypos == 0.0 && zpos == 0.0)
glRasterPos2i(screenX, screenY);
else
glRasterPos3f(xpos, ypos, zpos);
glPushAttrib(GL_LIST_BIT);
glListBase(callList - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
glPopMatrix();
}
/*********************************************************************/
/** Free the display list
**********************************************************************/
void CFont::ClearFont()
{
glDeleteLists(callList, 96);
}