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
|
#include "player.h"
#include <cmath>
Player::Player(uint32_t id, Vector3& pos, std::string name) {
this->id = id;
this->pos = pos;
this->name = name;
t = 0.0;
}
uint32_t Player::get_id() {
return id;
}
std::string Player::get_name() {
return name;
}
Vector3 Player::get_pos() {
return pos;
}
void Player::set_pos(Vector3& pos) {
this->pos = pos;
}
// TODO: find a sane way to do this
void Player::render(FTFont *font, unsigned int steps, GLuint texture) {
glPushMatrix();
glTranslatef(pos.x, pos.y, pos.z);
// billboarding setup
float modelview[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelview);
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
modelview[i*4+j] = i == j ? 1 : 0;
glLoadMatrixf(modelview);
// text rendering
glPushMatrix();
// probably not the best way to do calculate the text position, but it's accurate enough
FTBBox box = font->BBox(name.c_str());
FTPoint l = box.Lower();
FTPoint u = box.Upper();
float len = (Vector3(l.Xf(), l.Yf(), l.Zf()) - Vector3(u.Xf(), u.Yf(), u.Zf())).length();
// simplified from -len/72/2 + len/72/8
glTranslatef(-len/192, 2.1, 0);
glScalef(.01, .01, .01);
// make the text visible through terrain
glDisable(GL_DEPTH_TEST);
font->Render(name.c_str());
glEnable(GL_DEPTH_TEST);
glPopMatrix();
// GL_COLOR_BUFFER_BIT saves blending function
glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
t -= 0.0002 * steps;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
// quad with scrolling texture
glBegin(GL_QUADS);
glTexCoord2f(fmodf(t, 1) + .16, 1);
glVertex3f(-1, 0, 0);
glTexCoord2f(fmodf(t, 1), 1);
glVertex3f(1, 0, 0);
glTexCoord2f(fmodf(t, 1), 0);
glVertex3f(1, 2, 0);
glTexCoord2f(fmodf(t, 1) + .16, 0);
glVertex3f(-1, 2, 0);
glEnd();
glPopAttrib();
glBegin(GL_LINE_LOOP);
glVertex3f(-1, 0, .01);
glVertex3f(1, 0, .01);
glVertex3f(1, 2, .01);
glVertex3f(-1, 2, .01);
glEnd();
glPopMatrix(); // position translate
}
|