Font.h
Go to the documentation of this file.
1 #ifndef B_FONT_H
2 #define B_FONT_H
3 
4 #include <memory>
5 #include <string>
6 #include <map>
7 #include "Renderer_GL.h"
8 #include "Texture.h"
9 
10 #include "external/freetype-gl/freetype-gl.h"
11 
15 class Font
16 {
17 public:
18 
19  /* Functions */
20 
23  Font() { _initialized = false; }
24 
29  Font(const std::string &fontFileName, GLuint fontPixelSize);
30 
33  virtual ~Font() {
34  deleteFont();
35  }
36 
40  virtual void loadFont(const std::string &fontFileName){ init(fontFileName, _fontPixelSize); }
41 
45  virtual void setPixelSize(GLuint fontPixelSize) { init(_fontFileName, fontPixelSize); }
46 
49  GLuint getPixelSize() { return _fontPixelSize; }
50 
53  const std::string &getFontFileName() { return _fontFileName; }
54 
58  virtual ftgl::texture_glyph_t *getCharacter(char c);
59 
62  TexturePtr getAtlas(){ return _atlasTexture; }
63 
66  virtual void deleteFont();
67 
68 private:
69 
70  /* Functions */
71 
72  void init(const std::string &fontFileName, GLuint fontPixelSize);
73 
74  /* Variables */
75 
76  bool _initialized = false;
77  ftgl::texture_atlas_t *_atlas = nullptr;
78  ftgl::texture_font_t *_font = nullptr;
79  TexturePtr _atlasTexture = nullptr;
80  std::string _fontFileName;
81  GLuint _fontPixelSize;
82 };
83 
84 typedef std::shared_ptr< Font > FontPtr;
85 
86 #endif /* defined(B_FONT_H) */
virtual void setPixelSize(GLuint fontPixelSize)
Set the nominal font size in pixels (the characters may vary in size)
Definition: Font.h:45
std::shared_ptr< Font > FontPtr
Definition: Font.h:84
A font that can be used to display text. Characters can be accessed through a single texture atlas...
Definition: Font.h:15
std::shared_ptr< Texture > TexturePtr
Definition: Texture.h:67
Font()
Constructor.
Definition: Font.h:23
GLuint getPixelSize()
Returns the nominal font size in pixels (the characters may vary in size)
Definition: Font.h:49
virtual void loadFont(const std::string &fontFileName)
Loads a font file.
Definition: Font.h:40
TexturePtr getAtlas()
Returns the character atlas.
Definition: Font.h:62
virtual ftgl::texture_glyph_t * getCharacter(char c)
Returns a character.
Definition: Font.cpp:12
virtual void deleteFont()
Delete the font and its texture atlas.
Definition: Font.cpp:40
virtual ~Font()
Virtual destructor.
Definition: Font.h:33
const std::string & getFontFileName()
Returns the file name of the current font (including extension)
Definition: Font.h:53