-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3dtext.c
166 lines (126 loc) · 3.57 KB
/
3dtext.c
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "quakedef.h"
#include "mvd_cam.h"
#include <time.h>
#include <string.h>
#include "gl_model.h"
#include "gl_local.h"
void Draw_3D_Text(vec3_t position, vec3_t orientation, int x, int y, char *text, int type)
{
if (text == NULL)
return;
glPushMatrix();
glTranslatef(position[0], position[1], position[2]);
glRotatef(-90, 1, 0, 0);
Draw_ColoredString(x, y, text, 0);
glPopMatrix();
return;
}
void Draw_3D_Text_Scale(vec3_t position, vec3_t orientation, int x, int y, char *text, int type, float scale)
{
if (text == NULL)
return;
glPushMatrix();
glTranslatef(position[0], position[1], position[2]);
glRotatef(-90, 1, 0, 0);
glScalef(scale, scale, scale);
Draw_ColoredString(x, y, text, 0);
glPopMatrix();
return;
}
void mvd_vectoangles(vec3_t vec, vec3_t ang);
void Draw_3D_Text_Position(vec3_t position, vec3_t destination, int x, int y, char *text, int type, float scale)
{
vec3_t vec1, vec2, vec3,s, u, angles, billboard[4];
float m[16];
if (text == NULL)
return;
VectorSubtract(destination, position, vec1);
VectorCopy(vec1, vec2);
VectorNormalize(vec2);
VectorCopy(vup, vec3);
VectorNormalize(vec3);
CrossProduct(vec1, vec3,s);
CrossProduct(s, vec1,u);
VectorNormalize(s);
VectorNormalize(u);
m[0] = s[0]; m[1] = s[1]; m[2] = s[2]; m[3] = 0;
m[4] = u[0]; m[5] = u[1]; m[6] = u[2]; m[7] = 0;
m[8] = -vec2[0]; m[9] = -vec2[1]; m[10] = -vec2[2]; m[11] = 0;
m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;
glPushMatrix();
glTranslatef(position[0], position[1], position[2]);
glMultMatrixf(m);
glRotatef(180, 0, 0, 1);
glScalef(scale, scale, scale);
Draw_ColoredString(x, y, text, 0);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glColor4f(1,0,0,1);
glVertex3f(0,0,0);
glVertex3f(100,0, 0);
glEnd();
glBegin(GL_LINES);
glColor4f(0,1,0,1);
glVertex3f(0,0,0);
glVertex3f(0,100, 0);
glEnd();
glBegin(GL_LINES);
glColor4f(0,0,1,1);
glVertex3f(0,0,0);
glVertex3f(0,0,100);
glEnd();
glEnable(GL_TEXTURE_2D);
glPopMatrix();
return;
}
void Draw_3D_Text_Pop_Matrix(void)
{
glPopMatrix();
}
void Draw_3D_Text_Position_Setup_Matrix(vec3_t position, vec3_t destination, float scale)
{
vec3_t vec1, vec2, vec3,s, u, angles, billboard[4];
float m[16];
VectorSubtract(destination, position, vec1);
VectorCopy(vec1, vec2);
VectorNormalize(vec2);
VectorCopy(vup, vec3);
VectorNormalize(vec3);
CrossProduct(vec1, vec3,s);
CrossProduct(s, vec1,u);
VectorNormalize(s);
VectorNormalize(u);
m[0] = s[0]; m[1] = s[1]; m[2] = s[2]; m[3] = 0;
m[4] = u[0]; m[5] = u[1]; m[6] = u[2]; m[7] = 0;
m[8] = -vec2[0]; m[9] = -vec2[1]; m[10] = -vec2[2]; m[11] = 0;
m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;
glPushMatrix();
glTranslatef(position[0], position[1], position[2]);
glMultMatrixf(m);
glRotatef(180, 0, 0, 1);
glScalef(scale, scale, scale);
return;
}
void Draw_3D_Text_Setup_Drawable_Rectangle(int width, int height)
{
glClear(GL_STENCIL_BUFFER_BIT);
glClearStencil(0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 0x0, 0x0);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
glColor4f(0,0,0,0);
glRectf(0, 0, width, height);
glEnable(GL_ALPHA_TEST);
glStencilFunc(GL_EQUAL, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
}
void Draw_3D_Text_Remove_Drawable_Rectangle(void)
{
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
}