Josh's Graphics Library
FontCache.h
Go to the documentation of this file.
1#pragma once
2
3#include <glad/glad.h>
4#include <vector>
5#include <array>
6#include <unordered_map>
7
8
11
12namespace JGL {
13 class CachedGlyph;
14 class CachedFont;
15 class FontCache;
16}
17
20private:
21 char character;
22 std::array<GLfloat, 12> texcoords;
23public:
24 int x2offset = 0, y2offset = 0, w = 0, h = 0;
25 float advanceX = 0, advanceY = 0;
26
27 //CachedGlyph(GLuint texture_id, char c);
28 CachedGlyph(char c, std::array<GLfloat, 12> texcoords, float x2o, float y2o, float w, float h, float advX, float advY);
29 char getCharacter() const;
30 [[nodiscard]] std::array<GLfloat, 12> getTexCoords() const;
31};
32
35private:
36 std::unordered_map<char, CachedGlyph*> glyphs;
37 GLuint texture = 0;
38 GLsizei texture_width = 0, texture_height = 0;
39 unsigned int font_size = 0;
40 unsigned int font_index = 0;
41 void Erase();
42public:
43 void appendGlyph(CachedGlyph* glyph);
44 unsigned int getFontSize() const;
45 unsigned int getFontIndex() const;
46 CachedGlyph* getGlyph(char c);
47 std::unordered_map<char, CachedGlyph*> getGlyphs();
48 const GLuint* getTextureHandle();
49 [[nodiscard]] GLsizei getTextureWidth() const;
50 [[nodiscard]] GLsizei getTextureHeight() const;
51public:
52 CachedFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index);
54};
55
57private:
58 std::vector<CachedFont*> cachedFonts{};
59public:
60 std::vector<CachedFont*> getFonts();
61 CachedFont* getFont(unsigned int font_size, unsigned int font_index);
62 void appendFont(CachedFont* font);
63 void newFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index);
64 void eraseFont(CachedFont* font);
65 void purgeCache();
66};
67
68namespace JGL {
70}
Represents a Font object as it exists in the font-cache.
Definition: FontCache.h:34
~CachedFont()
Definition: FontCache.cpp:72
unsigned int getFontIndex() const
Definition: FontCache.cpp:32
GLsizei getTextureHeight() const
Definition: FontCache.cpp:63
std::unordered_map< char, CachedGlyph * > getGlyphs()
Definition: FontCache.cpp:51
unsigned int getFontSize() const
Definition: FontCache.cpp:28
const GLuint * getTextureHandle()
Definition: FontCache.cpp:55
CachedGlyph * getGlyph(char c)
Definition: FontCache.cpp:36
GLsizei getTextureWidth() const
Definition: FontCache.cpp:59
CachedFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index)
Definition: FontCache.cpp:43
void appendGlyph(CachedGlyph *glyph)
Definition: FontCache.cpp:24
Represents a single font-character "glyph", that has been cached in-memory for fast retrieval.
Definition: FontCache.h:19
int y2offset
Definition: FontCache.h:24
float advanceX
Definition: FontCache.h:25
CachedGlyph(char c, std::array< GLfloat, 12 > texcoords, float x2o, float y2o, float w, float h, float advX, float advY)
Definition: FontCache.cpp:13
std::array< GLfloat, 12 > getTexCoords() const
Definition: FontCache.cpp:9
int w
Definition: FontCache.h:24
float advanceY
Definition: FontCache.h:25
int x2offset
Definition: FontCache.h:24
int h
Definition: FontCache.h:24
char getCharacter() const
Definition: FontCache.cpp:5
Definition: FontCache.h:56
void purgeCache()
Definition: FontCache.cpp:94
void eraseFont(CachedFont *font)
Definition: FontCache.cpp:85
void appendFont(CachedFont *font)
Definition: FontCache.cpp:76
CachedFont * getFont(unsigned int font_size, unsigned int font_index)
Definition: FontCache.cpp:104
void newFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index)
Definition: FontCache.cpp:80
std::vector< CachedFont * > getFonts()
Definition: FontCache.cpp:100
OpenGL Wrapper for rendering 2D & 3D graphics in both a 2D and 3D context.
Definition: JGL.h:31
FontCache fontCache
Definition: FontCache.h:69