Font cache
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m34s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m34s
This commit is contained in:
53
include/JGL/FontCache.h
Normal file
53
include/JGL/FontCache.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <glad/glad.h>
|
||||
|
||||
namespace JGL {
|
||||
class CachedGlyph;
|
||||
class CachedFont;
|
||||
class FontCache;
|
||||
}
|
||||
|
||||
class JGL::CachedGlyph {
|
||||
private:
|
||||
GLuint texture = 0;
|
||||
char character;
|
||||
public:
|
||||
int x2offset = 0, y2offset = 0, w = 0, h = 0;
|
||||
float advanceX = 0, advanceY = 0;
|
||||
|
||||
//CachedGlyph(GLuint texture_id, char c);
|
||||
CachedGlyph(GLuint texture_id, char c, float x2o, float y2o, float w, float h, float advX, float advY);
|
||||
char getCharacter();
|
||||
const GLuint* getTexture();
|
||||
};
|
||||
|
||||
class JGL::CachedFont {
|
||||
private:
|
||||
std::vector<CachedGlyph*> glyphs{};
|
||||
unsigned int font_size = 0;
|
||||
unsigned int font_index = 0;
|
||||
public:
|
||||
void appendGlyph(CachedGlyph* glyph);
|
||||
void eraseGlyph(CachedGlyph* glyph);
|
||||
void eraseGlyph(char c);
|
||||
void eraseGlyph(GLuint texture_id);
|
||||
unsigned int getFontSize();
|
||||
unsigned int getFontIndex();
|
||||
CachedGlyph* getGlyph(char c);
|
||||
std::vector<CachedGlyph*>* getGlyphs();
|
||||
CachedFont(unsigned int font_size, unsigned int font_index);
|
||||
};
|
||||
|
||||
class JGL::FontCache {
|
||||
private:
|
||||
std::vector<CachedFont*> cachedFonts = {};
|
||||
public:
|
||||
std::vector<CachedFont*>* getFonts();
|
||||
CachedFont* getFont(unsigned int font_size, unsigned int font_index);
|
||||
void appendFont(CachedFont* font);
|
||||
void newFont(unsigned int font_size, unsigned int font_index);
|
||||
void eraseFont(CachedFont* font);
|
||||
void purgeCache();
|
||||
};
|
@@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <JGL/Color3.h>
|
||||
#include <JGL/FontCache.h>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
@@ -49,7 +50,9 @@ namespace JGL {
|
||||
};
|
||||
|
||||
bool InitTextEngine();
|
||||
inline FontCache fontCache;
|
||||
int LoadFont(const std::string& font_path);
|
||||
|
||||
void UnloadFont(int font_index);
|
||||
// TODO: implement correct coloring
|
||||
|
||||
|
Reference in New Issue
Block a user