#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(int size, const std::string& path = getDefaultPath()); ~Font(); FT_Face face; //contains sizing information for every glyph. struct charPosData { int texX; int texY; int texW; int texH; float advX; //!& rm) override; void reload(std::shared_ptr& rm) override; int getSize() const; static std::string getDefaultPath(); private: static int getDpiX(); static int getDpiY(); static FT_Library sLibrary; static bool libraryInitialized; static std::map< std::pair, std::weak_ptr > sFontMap; Font(int size, const std::string& path); 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; }; struct CacheMetrics { Eigen::Vector2f size; } metrics; void setColor(unsigned int color); TextCache(int verts, Vertex* v, GLubyte* c, const CacheMetrics& m); ~TextCache(); int vertCount; Vertex* verts; GLubyte* colors; }; #endif