You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
779 B

#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();
}