13#ifndef ML_GL_2D_FONT_H
14#define ML_GL_2D_FONT_H
26ML_OPENGL_START_NAMESPACE
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;
252ML_OPENGL_END_NAMESPACE
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.
bool isUnicodeRenderingPossible() const
Returns true if Unicode rendering is possible; otherwise, it returns false.
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.
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.
int getFontAscender(float fontSize) const
Returns the ascender of the font in pixels.
void postFontDraw(const bool overlay)
Finalizes the font rendering.
static std::string getDefaultSystemFontName()
Returns the default font name for proportional fonts.
bool reloadFonts()
Frees old fonts and reloads them.
std::string findFontFile(const char *fontName)
Searches for the file name of the given font.
bool init(const char *fontname)
Initializes the given font, which is either just a font name without .ttf or an absolute path.
void contextDestroyed() override
Forgets the resource, the context was destroyed (called by the GLResourceManager).
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 debugFontRenderingEnabled()
Checks whether debug font rendering is enabled.
std::string findFontFileWithFontconfig(const char *fontName)
Searches the font by using fontconfig (Linux only)
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,...
int getStringWidth(float fontSize, const char *string, int length=-1) const
Returns the width of the given simple string.
int getFontDescender(float fontSize) const
Returns the descender of the font in pixels (i.e., the positive distance from the baseline).
int getFontHeight(float fontSize) const
Returns the height of a font (ascender+descender) in pixels.
bool init()
Initializes with the default system font.
void preFontDraw(bool overlay)
Initializes font rendering.
bool isInitialized() const
Returns true if font loaded; otherwise, it returns false.
void cleanup()
Cleans up the fonts.
int getFontIndex(float fontSize) const
Returns the font index that should be used for the given size of the font.
Abstract base class for GLResources.
#define MLOPENGL_EXPORT
Macro to put all following code into the namespace ML_NAMESPACE to avoid collisions with symbols of o...