33 lines
779 B
C
33 lines
779 B
C
#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];
|
|
ftglGetFontBBox(font, text, -1, bounds);
|
|
int cx = bounds[3] - bounds[0];
|
|
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;
|
|
}
|
|
|
|
glPushMatrix();
|
|
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);
|
|
glPopMatrix();
|
|
}
|