13 #ifndef ML_GL_2D_FONT_H
14 #define ML_GL_2D_FONT_H
60 enum { MAX_FONTS = 32 };
73 bool init(
const char* fontname);
81 bool init(
const char* fontname,
int numFonts,
const int* sizes);
102 void drawString(
float dx,
float dy,
float fontSize,
const float color[4],
const char*
string,
size_t length = 0,
103 bool overlay =
false,
bool shadow =
true,
104 const float* shadowColor =
nullptr);
143 return _unicodeRendering;
195 void doFontDraw(
float dx,
float dy,
float fontSize,
const float color[4],
bool shadow,
196 const char* asciiString,
const wchar_t* optionalUnicodeString,
const float* shadowColor);
213 const char*
copyAndConvertString(
const char*
string,
size_t length,
const wchar_t** optionalUnicodeString)
const;
228 std::string _fontfile;
231 std::string _fallback;
237 FTFont* _font[MAX_FONTS];
240 float _fontSize[MAX_FONTS];
246 bool _unicodeRendering;
249 static GL2DFont* _defaultSystemFont;
A bridge to the FTGL library that manages font rendering with texture fonts.
bool checkUTF8StringForUnicodeChars(const char *string, size_t length=0) const
Checks whether the string contains unicode chars.
void drawString(float dx, float dy, float fontSize, const float color[4], const char *string, size_t length=0, bool overlay=false, bool shadow=true, const float *shadowColor=nullptr)
This function draws a simple string with no line feeds.
static GL2DFont * getDefaultSystemFont()
Returns the default system font.
const char * copyAndConvertString(const char *string, size_t length, const wchar_t **optionalUnicodeString) const
Internal method that copies the string to the internal buffer and generates a Unicode string if it is...
bool init(const char *fontname, int numFonts, const int *sizes)
Initializes the given font, which is either just a font name without .ttf or an absolute path,...
bool reloadFonts()
Frees old fonts and reloads them.
void contextDestroyed() override
Forgets the resource, the context was destroyed (called by the GLResourceManager).
bool isInitialized() const
Returns true if font loaded; otherwise, it returns false.
void postFontDraw(const bool overlay)
Finalizes the font rendering.
int getFontAscender(float fontSize) const
Returns the ascender of the font in pixels.
int getFontDescender(float fontSize) const
Returns the descender of the font in pixels (i.e., the positive distance from the baseline).
bool init()
Initializes with the default system font.
void cleanup()
Cleans up the fonts.
std::string findFontFileWithFontconfig(const char *fontName)
Searches the font by using fontconfig (Linux only)
bool debugFontRenderingEnabled()
Checks whether debug font rendering is enabled.
int getFontIndex(float fontSize) const
Returns the font index that should be used for the given size of the font.
int getFontHeight(float fontSize) const
Returns the height of a font (ascender+descender) in pixels.
static std::string getDefaultSystemFontName()
Returns the default font name for proportional fonts.
void preFontDraw(bool overlay)
Initializes font rendering.
void doFontDraw(float dx, float dy, float fontSize, const float color[4], bool shadow, const char *asciiString, const wchar_t *optionalUnicodeString, const float *shadowColor)
Renders the fonts.
bool isUnicodeRenderingPossible() const
Returns true if Unicode rendering is possible; otherwise, it returns false.
std::string findFontFile(const char *fontName)
Searches for the file name of the given font.
int getStringWidth(float fontSize, const char *string, int length=-1) const
Returns the width of the given simple string.
bool init(const char *fontname)
Initializes the given font, which is either just a font name without .ttf or an absolute path.
Collection of OpenGL related resource classes, such as textures, buffers, fragment programs etc.
#define ML_OPENGL_END_NAMESPACE
Closes the namespace for all ML code after the usage of ML_UTILS_START_NAMESPACE.
#define ML_OPENGL_START_NAMESPACE
Macro to put all following code into the namespace ML_NAMESPACE to avoid collisions with symbols of o...