lfsdash/text.c

33 lines
779 B
C
Raw Permalink Normal View History

2014-06-29 08:18:21 +00:00
#include <GL/glfw.h>
#include <FTGL/ftgl.h>
#include "text.h"
void drawText(const char *text, FTGLfont *font, float x, float y, float xs, float ys, int xa, int ya)
{
float bounds[6];
2014-06-28 22:49:09 +00:00
ftglGetFontBBox(font, text, -1, bounds);
int cx = bounds[3] - bounds[0];
2014-06-29 08:18:21 +00:00
int cy = bounds[4] - bounds[1];
float ox = 0, oy = 0;
switch (xa)
{
case TA_LEFT: ox = 0; break;
case TA_RIGHT: ox = -1; break;
case TA_CENTRE: ox = -0.5; break;
}
switch (ya)
{
case TA_TOP: oy = -1; break;
case TA_BOTTOM: oy = 0; break;
case TA_CENTRE: oy = -0.5; break;
2014-06-28 22:49:09 +00:00
}
2014-06-29 08:18:21 +00:00
glPushMatrix();
2014-06-28 22:49:09 +00:00
glTranslatef(x, y, 0.0f);
glScalef(xs / TEXT_SIZE, ys / TEXT_SIZE, 1.0f);
glTranslatef(cx * ox, cy * oy, 0.0f);
ftglRenderFont(font, text, FTGL_RENDER_ALL);
2014-06-29 08:18:21 +00:00
glPopMatrix();
}