-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinfont.cpp
More file actions
130 lines (107 loc) · 2.61 KB
/
winfont.cpp
File metadata and controls
130 lines (107 loc) · 2.61 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
123
124
125
126
127
128
129
130
#include "winfont.h"
GLuint textBase = 0;
GLuint startTextModeList = 0;
#pragma warning ( disable:4996 )
int GetCharFontWidth(const char cCharacter)
{
HWND hWnd = win_get_window();
HDC hDC = GetDC(hWnd);
SIZE kSize;
GetTextExtentPoint32(hDC, &cCharacter, 1, &kSize);
ReleaseDC(hWnd, hDC);
return (int)kSize.cx;
}
int Font_Init(int sizept)
{
TEXTMETRIC kMetric;
HWND hwnd;
HFONT font;
HFONT oldfont;
HDC hdc;
long lfHeight;
hwnd = win_get_window();
hdc = GetDC(hwnd);
//Create 96 display lists
textBase = glGenLists(96);
if (textBase == 0)
{
wrlog("Unable to create 96 display lists for font");
return 0;
}
lfHeight = -MulDiv(sizept, GetDeviceCaps(hdc, LOGPIXELSY), 72);
//Create font
font = CreateFont(lfHeight, //height -18
0, //default width,
0, 0, //angles
FW_BOLD, //bold
0, //italic
0, //underline
0, //strikeout
ANSI_CHARSET, //character set
OUT_TT_PRECIS, //precision
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, //quality
FF_DONTCARE | DEFAULT_PITCH,
"Arial");
//Select font
oldfont = (HFONT)SelectObject(hdc, font);
//Fill in the 96 display lists, starting with character 32
wglUseFontBitmaps(hdc, 32, 96, textBase);
GetTextMetrics(hdc, &kMetric);
SelectObject(hdc, oldfont); // Selects The Previous Font
DeleteObject(font); //Cleanup
wrlog("Font created successfully");
return 1;
}
//Start text mode
void StartTextMode(void)
{
//Create a display list if not already done
if (!startTextModeList)
{
startTextModeList = glGenLists(1);
glNewList(startTextModeList, GL_COMPILE);
{
glListBase(textBase - 32);
ViewOrtho(SCREEN_W, SCREEN_H);
//Set states
glDisable(GL_DEPTH_TEST);
}
glEndList();
}
//Call the list
// glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glCallList(startTextModeList);
// glPopAttrib();
}
//Print some text
void Font_Print(int x, int y, const char* string, ...)
{
//Convert to text
static char text[256];
va_list va;
if (string == NULL)
return;
va_start(va, string);
vsprintf(text, string, va);
va_end(va);
//Print the text
glRasterPos2i(x, y);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
}
//End text mode
void EndTextMode(void)
{
//restore matrices
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
//reset other states
glListBase(0);
//glEnable(GL_DEPTH_TEST);
}
void KillFont() // Delete The Font List
{
glDeleteLists(textBase, 96); // Delete All 96 Characters ( NEW )
}