#ifndef _FONT_H_ #define _FONT_H_ #include #include "platform.h" #include GLHEADER #include #include FT_FREETYPE_H #include #include "resources/ResourceManager.h" class TextCache; #define FONT_SIZE_SMALL ((unsigned int)(0.035f * Renderer::getScreenHeight())) #define FONT_SIZE_MEDIUM ((unsigned int)(0.045f * Renderer::getScreenHeight())) #define FONT_SIZE_LARGE ((unsigned int)(0.1f * Renderer::getScreenHeight())) //A TrueType Font renderer that uses FreeType and OpenGL. //The library is automatically initialized when it's needed. class Font : public IReloadable { public: static void initLibrary(); static std::shared_ptr get(ResourceManager& rm, const std::string& path, int size); ~Font(); FT_Face face; //contains sizing information for every glyph. struct charPosData { int texX; int texY; int texW; int texH; float advX; //!, std::weak_ptr > sFontMap; Font(const ResourceManager& rm, const std::string& path, int size); void init(ResourceData data); void deinit(); void buildAtlas(ResourceData data); //Builds a "texture atlas," one big OpenGL texture with glyphs 32 to 128. int textureWidth; //OpenGL texture width int textureHeight; //OpenGL texture height int mMaxGlyphHeight; float fontScale; //! 1.0 if the font would be to big for the texture int mSize; const std::string mPath; }; class TextCache { public: struct Vertex { Eigen::Vector2f pos; Eigen::Vector2f tex; }; void setColor(unsigned int color); TextCache(int verts, Vertex* v, GLubyte* c, Font* f); ~TextCache(); const int vertCount; const Vertex* verts; const GLubyte* colors; const Font* sourceFont; }; #endif