2014-02-16 14:32:28 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
#include "font.h"
|
|
|
|
#include "glapi.h"
|
2015-06-02 20:25:50 +00:00
|
|
|
#include <string.h>
|
2014-02-16 14:32:28 +00:00
|
|
|
|
|
|
|
Texture *fonttexture;
|
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
void drawChar(float x, float y, char ch, float size) {
|
|
|
|
fonttexture->enable();
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
int tx = (ch & 15) * 64;
|
|
|
|
int ty = (ch >> 4) * 64;
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
float w = size, h = size * 4 / 3;
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2f((tx) / 1024.0, (ty) / 1024.0);
|
|
|
|
glVertex2f(x, y);
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
glTexCoord2f((tx) / 1024.0, (ty + 64) / 1024.0);
|
|
|
|
glVertex2f(x, y + h);
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
glTexCoord2f((tx + 64) / 1024.0, (ty + 64) / 1024.0);
|
|
|
|
glVertex2f(x + w, y + h);
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
glTexCoord2f((tx + 64) / 1024.0, (ty) / 1024.0);
|
|
|
|
glVertex2f(x + w, y);
|
2014-02-16 14:32:28 +00:00
|
|
|
|
2015-06-03 12:29:34 +00:00
|
|
|
glEnd();
|
2014-02-16 14:32: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0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
|
|
|
|
|
|
|
|
void print(float x, float y, char *text, float size) {
|
|
|
|
int i;
|
|
|
|
int textlength = strlen(text);
|
|
|
|
float px = x;
|
|
|
|
float py = y;
|
|
|
|
for (i = 0; i < textlength; i++) {
|
2015-06-02 20:25:50 +00:00
|
|
|
unsigned char ch = text[i];
|
2015-06-03 12:29:34 +00:00
|
|
|
if (ch == '\n') {
|
|
|
|
px = x;
|
|
|
|
py += size * 1.2;
|
|
|
|
} else {
|
|
|
|
drawChar(px, py, ch, size);
|
|
|
|
px += size * letterwidth[ch];
|
2014-02-16 14:32:28 +00:00
|
|
|
}
|
2015-06-03 12:29:34 +00:00
|
|
|
}
|
2014-02-16 14:32:28 +00:00
|
|
|
}
|