2012-08-29 18:53:53 +00:00
|
|
|
|
|
|
|
#ifndef _FONT_H_
|
|
|
|
#define _FONT_H_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <GLES/gl.h>
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//A TrueType Font renderer that uses FreeType and OpenGL. initLibrary() MUST be called before using it.
|
2012-08-29 18:53:53 +00:00
|
|
|
class Font
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void initLibrary();
|
|
|
|
|
|
|
|
Font(std::string path, int size);
|
|
|
|
~Font();
|
|
|
|
|
|
|
|
FT_Face face;
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
//contains sizing information for every glyph.
|
2012-08-29 18:53:53 +00:00
|
|
|
struct charPosData {
|
|
|
|
int texX;
|
|
|
|
int texY;
|
|
|
|
int texW;
|
|
|
|
int texH;
|
|
|
|
|
|
|
|
int advX;
|
|
|
|
int advY;
|
|
|
|
|
|
|
|
int bearingY;
|
|
|
|
};
|
|
|
|
|
|
|
|
charPosData charData[128];
|
|
|
|
|
|
|
|
GLuint textureID;
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
void drawText(std::string text, int startx, int starty, int color); //Render some text using this font.
|
|
|
|
void sizeText(std::string text, int* w, int* h); //Sets the width and height of a given string to given pointers. Skipped if pointer is NULL.
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
private:
|
2012-08-29 18:53:53 +00:00
|
|
|
static int getDpiX();
|
|
|
|
static int getDpiY();
|
|
|
|
static FT_Library sLibrary;
|
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
void buildAtlas(); //Builds a "texture atlas," one big OpenGL texture with glyphs 32 to 128.
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-09-07 21:44:07 +00:00
|
|
|
int textureWidth; //OpenGL texture width
|
|
|
|
int textureHeight; //OpenGL texture height
|
2012-08-29 21:52:25 +00:00
|
|
|
int mMaxGlyphHeight;
|
2012-08-29 18:53:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|