feat: add font class and render font function

This commit is contained in:
2026-03-28 12:04:31 +08:00
parent 93fbbaca2b
commit c37c45ad19
10 changed files with 217 additions and 11 deletions

View File

@@ -16,9 +16,11 @@ public:
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
static void window_focus_callback(GLFWwindow* window, int focused);
static void window_reshape_callback(GLFWwindow* window, int new_width, int new_height);
static int start_cubed_application(int argc, char** argv);
static float delte_time();
static float get_fps();
private:
Camera m_camera;
TextureManager m_texture_manager;
@@ -30,7 +32,12 @@ private:
GLuint m_texture_array;
inline static double last_time = glfwGetTime();
inline static double current_time = glfwGetTime();
inline static double delta_time = 0.0f;
inline static double fps_time_count = 0.0f;
inline static int frame_count = 0;
inline static int fps;
void init();

View File

@@ -30,11 +30,13 @@ private:
GLuint m_proj_loc;
GLuint m_sky_vbo;
GLuint m_text_vbo;
GLuint m_outline_indices_vbo;
GLuint m_outline_vbo;
GLuint m_ui_vbo;
GLuint m_sky_program;
GLuint m_text_program;
GLuint m_outline_program;
GLuint m_ui_program;
GLuint m_world_program;
@@ -47,5 +49,7 @@ private:
std::vector<Vertex2D> m_ui;
void render_outline();
void render_sky();
void render_text();
void render_ui();
};

View 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();
};