forked from YuantongL/3D-Graphics-Learning-through-Games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
word.cpp
executable file
·57 lines (48 loc) · 1.35 KB
/
word.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
50
51
52
53
54
55
56
57
#include "word.h"
#define MAX_CHAR 128
word::word(float pos[3], bool appear, int size, float color[4], char *disp, char *font)
{
for (int i = 0; i < 3; i++)
{
word_pos[i] = pos[i];
}
for (int i = 0; i < 3; i++)
{
word_color[i] = color[i];
}
word_disp = disp;
word_font = font;
word_size = size;
word_appear = appear;
}
void word::drawself()
{
if (word_appear == true)
{
glColor4f(word_color[0], word_color[1], word_color[2], word_color[3]); //设置字体颜色
glRasterPos2f(word_pos[0], word_pos[1]); //起始位置
selectFont(word_size, ANSI_CHARSET, word_font);
drawString(word_disp);
}
}
void word::drawString(char* str) //屏幕显示字体
{
if (isFirstCall) {
isFirstCall = 0;
// 申请MAX_CHAR个连续的显示列表编号
lists = glGenLists(MAX_CHAR);
// 把每个字符的绘制命令都装到对应的显示列表中
wglUseFontBitmaps(wglGetCurrentDC(), 0, MAX_CHAR, lists);
}
// 调用每个字符对应的显示列表,绘制每个字符
for (; *str != '\0'; ++str) {
glCallList(lists + *str);
}
}
void word::selectFont(int size, int charset, char* face) {
HFONT hFont = CreateFontA(size, 0, 0, 0, FW_MEDIUM, 0, 0, 0,
charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, face);
HFONT hOldFont = (HFONT)SelectObject(wglGetCurrentDC(), hFont);
DeleteObject(hOldFont);
}