34 std::ifstream file(font, std::ios::in | std::ios::binary);
35 unsigned char* pixels =
new unsigned char[256 * 256 * 4];
36 if (!file.read((
char*)pixels, 256 * 256 * 4)) {
42 for (
unsigned int i = 0; i < (256 * 256 * 4); i += 4) {
43 float y = (0.2126f * pixels[i + 2]);
44 y += (0.7152f * pixels[i + 1]);
45 y += (0.0722f * pixels[i]);
46 pixels[i] = pixels[i + 1] = pixels[i + 2] = (
unsigned char)y;
63 std::ifstream file(f);
69 for (std::string line; std::getline(file, line);) {
70 std::istringstream stream(line);
73 if (stream.get() !=
'=')
76 if (stream.get() !=
',')
78 stream >> offsets[index][1];
79 if (stream.get() !=
',')
81 stream >> offsets[index][2];
82 if (stream.get() !=
',')
84 stream >> offsets[index][3];
85 if (stream.get() !=
',')
87 stream >> offsets[index][4];
92 std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs) {
101 float yMin = yDraw + offset + (10.0f * scale *
SCALING);
102 float xMax = xMin + width;
103 float yMax = yMin + height;
106 float txMin = ((float)
offsets[index][0]) / 256.0f;
107 float txMax = ((float)(
offsets[index][0] +
offsets[index][2])) / 256.0f;
108 float tyMin = ((float)
offsets[index][1]) / 256.0f;
109 float tyMax = ((float)(
offsets[index][1] +
offsets[index][3])) / 256.0f;
111 vertices.push_back(glm::vec2(xMin, yMax));
112 vertices.push_back(glm::vec2(xMin, yMin));
113 vertices.push_back(glm::vec2(xMax, yMax));
115 vertices.push_back(glm::vec2(xMax, yMin));
116 vertices.push_back(glm::vec2(xMax, yMax));
117 vertices.push_back(glm::vec2(xMin, yMin));
119 uvs.push_back(glm::vec2(txMin, tyMax));
120 uvs.push_back(glm::vec2(txMin, tyMin));
121 uvs.push_back(glm::vec2(txMax, tyMax));
123 uvs.push_back(glm::vec2(txMax, tyMin));
124 uvs.push_back(glm::vec2(txMax, tyMax));
125 uvs.push_back(glm::vec2(txMin, tyMin));
132 unsigned int width = 0;
133 for (
unsigned int i = 0; i < s.length(); i++) {
135 int index = s[i] -
'!';
138 width += (
unsigned int)(14.0f * scale *
SCALING);
140 if ((index < 0) || (index > 105))
150 glm::vec4 color, std::string s) {
154 std::vector<glm::vec2> vertices;
155 std::vector<glm::vec2> uvs;
156 for (
unsigned int i = 0; i < s.length(); i++) {
158 int index = s[i] -
'!';
161 x += (
unsigned int)(14.0f * scale *
SCALING);
163 if ((index < 0) || (index > 105))
166 writeChar((
unsigned int)index, x, y, scale, vertices, uvs);
167 x += (int)((
float)(
offsets[index][2] + 1) * scale * SCALING);
180 unsigned int yMax = 0;
181 unsigned int yReturn = 0;
183 for (
unsigned int i = 0; i < s.length(); i++) {
185 int index = s[i] -
'!';
188 x += (
unsigned int)(14.0f * scale *
SCALING);
190 if ((index < 0) || (index > 105))
193 if (yMax < (
unsigned int)(((float)
offsets[index][3]) * scale *
SCALING))
194 yMax = (
unsigned int)(((
float)
offsets[index][3]) * scale * SCALING);
196 x += (int)((
float)(
offsets[index][2] + 1) * scale * SCALING);
201 x = (int)((
float)(
offsets[index][2] + 1) * scale * SCALING);
205 return yReturn + yMax + 2;
209 glm::vec4 color,
unsigned int maxWidth, std::string s) {
213 unsigned int xStart = x;
214 unsigned int yMax = 0;
216 std::vector<glm::vec2> vertices;
217 std::vector<glm::vec2> uvs;
218 for (
unsigned int i = 0; i < s.length(); i++) {
220 int index = s[i] -
'!';
223 x += (
unsigned int)(14.0f * scale *
SCALING);
225 if ((index < 0) || (index > 105))
228 if (yMax < (
unsigned int)(((float)
offsets[index][3]) * scale *
SCALING))
229 yMax = (
unsigned int)(((
float)
offsets[index][3]) * scale * SCALING);
231 x += (int)((
float)(
offsets[index][2] + 1) * scale * SCALING);
232 if ((x - xStart) > maxWidth) {
238 x -= (int)((
float)(
offsets[index][2] + 1) * scale * SCALING);
241 writeChar((
unsigned int)index, x, y, scale, vertices, uvs);
242 x += (int)((
float)(
offsets[index][2] + 1) * scale * SCALING);
251 { 174, 52, 3, 12, -11 },
252 { 98, 58, 6, 4, -10 },
253 { 82, 26, 13, 11, -10 },
254 { 78, 38, 9, 13, -10 },
255 { 214, 13, 14, 11, -9 },
256 { 40, 26, 13, 11, -10 },
257 { 157, 57, 5, 6, -11 },
258 { 204, 39, 5, 15, -12 },
259 { 34, 40, 5, 15, -12 },
260 { 184, 59, 4, 4, -11 },
261 { 22, 40, 10, 10, -9 },
262 { 178, 59, 4, 4, -2 },
263 { 106, 60, 7, 2, -4 },
264 { 114, 60, 4, 3, -2 },
265 { 212, 38, 8, 14, -12 },
266 { 88, 49, 9, 9, -8 },
267 { 200, 55, 5, 9, -8 },
268 { 46, 52, 8, 9, -8 },
269 { 88, 38, 7, 10, -8 },
270 { 62, 40, 10, 10, -8 },
271 { 142, 48, 8, 11, -9 },
272 { 232, 50, 8, 10, -9 },
273 { 120, 47, 8, 11, -9 },
274 { 22, 51, 8, 10, -9 },
275 { 110, 49, 8, 10, -8 },
276 { 152, 57, 4, 7, -7 },
277 { 136, 57, 4, 9, -7 },
278 { 178, 40, 11, 9, -8 },
279 { 210, 53, 10, 6, -7 },
280 { 240, 40, 11, 9, -7 },
281 { 12, 39, 9, 12, -11 },
282 { 66, 13, 15, 13, -10 },
283 { 130, 13, 13, 12, -11 },
284 { 214, 25, 12, 12, -11 },
285 { 132, 35, 10, 12, -11 },
286 { 0, 26, 12, 12, -11 },
287 { 14, 26, 12, 12, -11 },
288 { 66, 27, 11, 12, -11 },
289 { 182, 27, 11, 12, -11 },
290 { 200, 13, 13, 12, -11 },
291 { 222, 54, 4, 12, -11 },
292 { 56, 52, 4, 15, -11 },
293 { 230, 15, 12, 12, -11 },
294 { 144, 35, 10, 12, -11 },
295 { 48, 13, 17, 12, -11 },
296 { 144, 13, 13, 12, -11 },
297 { 54, 26, 11, 12, -11 },
298 { 200, 26, 11, 12, -11 },
299 { 240, 0, 13, 14, -11 },
300 { 158, 13, 13, 12, -11 },
301 { 156, 35, 10, 12, -11 },
302 { 172, 13, 13, 12, -11 },
303 { 98, 13, 14, 12, -11 },
304 { 82, 13, 14, 12, -11 },
305 { 24, 13, 22, 12, -11 },
306 { 186, 13, 12, 13, -11 },
307 { 114, 13, 14, 12, -11 },
308 { 228, 28, 11, 12, -11 },
309 { 62, 60, 5, 3, -4 },
310 { 248, 59, 5, 3, -4 },
311 { 88, 59, 7, 3, -4 },
312 { 142, 60, 6, 2, -3 },
313 { 120, 59, 7, 3, -4 },
314 { 242, 59, 4, 4, -11 },
315 { 98, 49, 10, 8, -7 },
316 { 96, 35, 10, 13, -12 },
317 { 72, 52, 8, 8, -7 },
318 { 0, 39, 10, 11, -10 },
319 { 164, 52, 8, 8, -7 },
320 { 168, 38, 9, 13, -12 },
321 { 120, 35, 11, 11, -7 },
322 { 108, 35, 10, 13, -12 },
323 { 194, 27, 5, 11, -10 },
324 { 40, 51, 5, 15, -10 },
325 { 28, 26, 11, 13, -12 },
326 { 82, 52, 5, 12, -11 },
327 { 96, 26, 17, 8, -7 },
328 { 152, 48, 11, 8, -7 },
329 { 62, 51, 9, 8, -7 },
330 { 244, 15, 10, 12, -7 },
331 { 52, 39, 9, 12, -7 },
332 { 10, 52, 9, 8, -7 },
333 { 190, 52, 8, 8, -7 },
334 { 0, 51, 8, 10, -9 },
335 { 178, 50, 10, 8, -7 },
336 { 130, 48, 11, 8, -7 },
337 { 132, 26, 17, 8, -7 },
338 { 242, 50, 10, 8, -7 },
339 { 40, 38, 10, 12, -7 },
340 { 232, 41, 7, 8, -7 },
341 { 222, 41, 8, 12, -7 },
342 { 130, 57, 5, 8, -7 },
343 { 194, 39, 9, 12, -10 },
344 { 32, 56, 4, 11, -10 },
345 { 1, 14, 22, 11, -10 },
346 { 192, 0, 23, 13, -10 },
347 { 168, 0, 23, 12, -10 },
348 { 216, 0, 23, 12, -10 },
349 { 150, 26, 17, 8, -8 },
350 { 168, 26, 11, 11, -9 },
351 { 114, 26, 17, 8, -8 },
352 { 240, 28, 12, 11, -9 },
353 { 0, 0, 40, 12, -10 },
354 { 84, 0, 39, 11, -10 },
355 { 42, 0, 39, 11, -10 },
356 { 126, 0, 39, 11, -10 },
void bufferData(int elem, int size, void *data)
String handling utilities.
static void drawText(unsigned int x, unsigned int y, float scale, glm::vec4 color, std::string s)
static int initialize(std::string font)
OpenGL Shader Implementation.
static unsigned int widthText(float scale, std::string s)
static unsigned int heightText(float scale, unsigned int maxWidth, std::string s)
static void loadLPS(std::string f)
bool stringEndsWith(std::string s, std::string suffix, bool casesensitive=false)
static void drawGL(ShaderBuffer &vertices, ShaderBuffer &uvs, glm::vec4 color, unsigned int texture, TextureStorage store=TextureStorage::SYSTEM, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=textShader)
static ShaderBuffer vertexBuffer
static unsigned int mFontTexture
static int offsets[106][5]
static int defaultOffsets[106][5]
static void drawTextWrapped(unsigned int x, unsigned int y, float scale, glm::vec4 color, unsigned int maxWidth, std::string s)
std::string findAndReplace(std::string s, std::string find, std::string replace)
static ShaderBuffer uvBuffer
static void writeChar(unsigned int index, unsigned int xDraw, unsigned int yDraw, float scale, std::vector< glm::vec2 > &vertices, std::vector< glm::vec2 > &uvs)
static int loadBufferSlot(unsigned char *image=nullptr, unsigned int width=256, unsigned int height=256, ColorMode mode=ColorMode::RGBA, unsigned int bpp=32, TextureStorage s=TextureStorage::GAME, int slot=-1, bool filter=true)
Loads Buffer as texture.
Tomb Raider Level Editor Font loader.