-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextRenderer.h
59 lines (51 loc) · 1.31 KB
/
textRenderer.h
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
#ifndef __TEXTRENDERER_CARDACE_H_
#define __TEXTRENDERER_CARDACE_H_
#include <GL/glew.h>
#include <SDL2/SDL_ttf.h>
#include <vector>
class Glyph {
public:
Glyph(char c, int a, int mny, int mxy, int mnx, int mxx, GLuint tex) {
letter = c;
advance = a;
maxx = mxx;
maxy = mxy;
minx = mnx;
miny = mny;
texture = tex;
}
char getChar() const { return letter; };
int getTextureID() const { return texture; };
int getAdvance() const { return advance; };
int getMaxY() const { return maxy; };
int getMaxX() const { return maxx; };
int getMinX() const { return minx; };
int getMinY() const { return miny; };
private:
char letter;
GLuint texture;
int advance;
int maxx;
int maxy;
int minx;
int miny;
};
class TextRenderer {
public:
TextRenderer(char *fontPath, unsigned int fontSize);
void renderChar(char letter, int x, int y);
void renderText(char *str, int x, int y);
int getWidth(const char *str); // width of the rendered text in pixels
int getHeight();
void quit();
private:
void initTextures();
Glyph &getGlyph(std::size_t idx) { return glyphs.at(idx - 0x20); };
std::vector<Glyph> glyphs;
TTF_Font *font;
int outline;
int fontHeight;
/* Use reference counting to init and quit the TTF library */
static unsigned int referenceCounter;
};
#endif