-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgltext.cpp
More file actions
56 lines (47 loc) · 1.41 KB
/
Copy pathgltext.cpp
File metadata and controls
56 lines (47 loc) · 1.41 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
#include "gltext.h"
//https://guidedhacking.com/threads/opengl-hooking-drawing-text-rendering.14460/
void GL::Font::Build(int height)
{
hdc = wglGetCurrentDC();
base = glGenLists(96);
HFONT hFont = CreateFontA(-height, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Consolas");
HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
wglUseFontBitmaps(hdc, 32, 96, base);
SelectObject(hdc, hOldFont);
DeleteObject(hFont);
bBuilt = true;
}
void GL::Font::Print(float x, float y, const unsigned char color[3], const char* format, ...)
{
glColor3ub(color[0], color[1], color[2]);
glRasterPos2f(x, y);
char text[100];
va_list args;
va_start(args, format);
vsprintf_s(text, 100, format, args);
va_end(args);
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
vec3 GL::Font::centerText(float x, float y, float width, float height, float textWidth, float textHeight)
{
vec3 text;
text.x = x + (width - textWidth) / 2;
text.y = y + textHeight;
return text;
}
float GL::Font::centerText(float x, float width, float textWidth)
{
if (width > textWidth)
{
float difference = width - textWidth;
return (x + (difference / 2));
}
else
{
float difference = textWidth - width;
return (x - (difference / 2));
}
}