mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
feat: add font class and render font function
This commit is contained in:
35
include/Cubed/tools/font.hpp
Normal file
35
include/Cubed/tools/font.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
struct Character {
|
||||
GLuint texture_id;
|
||||
glm::ivec2 size;
|
||||
glm::ivec2 bearing;
|
||||
GLuint advance;
|
||||
};
|
||||
|
||||
class Font {
|
||||
public:
|
||||
Font();
|
||||
~Font();
|
||||
|
||||
static void render_text(GLuint program, GLuint vbo, const std::string& text, float x, float y, float scale, const glm::vec3& color);
|
||||
|
||||
private:
|
||||
FT_Library m_ft;
|
||||
FT_Face m_face;
|
||||
|
||||
std::unordered_map<char8_t, Character> m_characters;
|
||||
|
||||
void load_character(char8_t c);
|
||||
void setup_font_character();
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user