-
Notifications
You must be signed in to change notification settings - Fork 1
/
FontEngine.h
114 lines (83 loc) · 3.02 KB
/
FontEngine.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
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
#ifndef FONTENGINE_H
#define FONTENGINE_H
#include <string>
#include <unordered_map>
#include "includes.h"
#include "FontAtlas.h"
#include "Program.h"
using namespace std;
class FontEngine {
public:
FontEngine(int width, int height, Program *_prog, Program* _default);
~FontEngine();
bool init(GLuint _ShadeProg);
// load a font from fontFile and map it to given handle
// returns whether or not font was successfully added
bool addFont(std::string handle, std::string fontFile);
// set font handle to be active font with given size
// returns whether or not active font successfully set
bool useFont(std::string handle, int size);
// returns handle of the active font
std::string getCurrentHandle();
// returns current size of the active font
int getCurrentSize();
// set active color to render with
void setColor(float r, float g, float b, float a);
// set active z pos to render at
void setZ(float z);
// render text with currently active font at x,y [-1,1]
void renderText(std::string text, float x, float y);
void renderTextWrapped(std::string text, float x, float y, float width);
// get line height of active font
float getMaxCharHeight();
float getLineHeight();
void addLineHeight(float val);
// get width of given text
float getTextWidth(std::string text);
float getTextHeight(std::string text);
void updateWindowSize(int width, int height);
void display(glm::vec4 col, const char* text, float x, float y);
private:
// was the engine intialized successfully?
bool initialized;
// modify scaling by aspect ratio and to
// better match with expected scaling for font sizes
void adjustScaling(float &sx, float &sy);
FT_Library library;
Program* prog;
Program* dflt;
typedef struct Font {
FT_Face face;
std::string fontFile;
// mapping of sizes to atlas's
std::unordered_map<int, FontAtlas*> sizes;
} Font;
// mapping of handles to fonts
std::unordered_map<std::string, Font*> fonts;
// current font atlas to use for rendering
FontAtlas *curAtlas;
// handle of the current font
std::string currentHandle;
// current size of the active font
int currentSize;
// current color to use for rendering
GLfloat color[4];
// current zPos to use for rendering
float zPos;
struct Point {
GLfloat x, y;
GLfloat s, t;
};
// shader interface
GLuint ShadeProg;
GLint h_aCoord;
GLint h_uTex;
GLint h_uCol;
GLuint vbo;
int windowWidth, windowHeight;
std::string ostrichHandle;
std::string goodDogHandle;
std::string seasideHandle;
};
extern FontEngine* fontEngine;
#endif