-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpriteText.cpp
76 lines (67 loc) · 1.5 KB
/
SpriteText.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <gl/gl.h>
#include <sstream>
using std::ostringstream;
#include "SpriteText.h"
SpriteText::SpriteText(const Sprite& _sprite)
: sprite(_sprite), color{1.f, 1.f, 1.f}
{
}
SpriteText::~SpriteText()
{
}
void SpriteText::draw(float2 position, float orientation, float scale)
{
if (text.empty()) return;
glPushMatrix();
glColor3fv(color);
glLoadIdentity();
glTranslatef(position.x, position.y, -1.f);
glRotatef(orientation, 0,0,1);
glScalef(scale, scale, scale);
for (unsigned int i=0; i<text.length(); ++i)
{
sprite.play( text[i], text[i] );
sprite.draw(float2(i,0), 0.f, 1.f);
}
glColor3f(1.f, 1.f, 1.f);
glPopMatrix();
}
void SpriteText::draw(float orientation, float scale)
{
if (text.empty()) return;
glPushMatrix();
glColor3fv(color);
glLoadIdentity();
glTranslatef(pos.x, pos.y, -1.f);
glRotatef(orientation, 0,0,1);
glScalef(scale, scale, scale);
for (unsigned int i=0; i<text.length(); ++i)
{
sprite.play( text[i], text[i] );
sprite.draw(float2(i,0), 0.f, 1.f);
}
glColor3f(1.f, 1.f, 1.f);
glPopMatrix();
}
void SpriteText::setColor(float r, float g, float b)
{
color[0] = r;
color[1] = g;
color[2] = b;
}
void SpriteText::setText(const char *s)
{
text = s;
}
void SpriteText::setText(const char *s, int i)
{
ostringstream o;
o<<s<<i;
text = o.str();
}
void SpriteText::setText(int i,const char *s2)
{
ostringstream o;
o<<i<<s2;
text = o.str();
}