From d00ada1391d5f09bd3ce895f89e413929ff77dd6 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Sun, 12 Jul 2026 20:33:24 +0800 Subject: [PATCH] fix(font): use correct texture format and clamp to edge for font atlas --- include/Cubed/render/texture.hpp | 1 + src/tools/font.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/Cubed/render/texture.hpp b/include/Cubed/render/texture.hpp index b19bb7a..b135261 100644 --- a/include/Cubed/render/texture.hpp +++ b/include/Cubed/render/texture.hpp @@ -35,6 +35,7 @@ enum TextureFormat : GLenum { RGBA16F = GL_RGBA16F, RED = GL_RED, RGBA = GL_RGBA, + R8 = GL_R8, RGB = GL_RGB, RGBA8 = GL_RGBA8, diff --git a/src/tools/font.cpp b/src/tools/font.cpp index fd01166..9bda679 100644 --- a/src/tools/font.cpp +++ b/src/tools/font.cpp @@ -38,9 +38,9 @@ void Font::load_character(char8_t c) { static_cast(c), width, height); Character character = { - glm::vec2{0.0f, 0.0f}, - glm::vec2{static_cast(width) / m_texture_width, - static_cast(height) / m_texture_height}, + glm::vec2{0.5f / m_texture_width, 0.5f / m_texture_height}, + glm::vec2{(width - 0.5f) / m_texture_width, + (height - 0.5f) / m_texture_height}, glm::ivec2(m_face->glyph->bitmap.width, m_face->glyph->bitmap.rows), glm::ivec2(m_face->glyph->bitmap_left, m_face->glyph->bitmap_top), static_cast(m_face->glyph->advance.x)}; @@ -51,7 +51,7 @@ void Font::load_character(char8_t c) { void Font::setup_font_character() { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); m_text_texture = std::make_unique(TextureType::TEXTURE_2D_ARRAY); - m_text_texture->tex_image_3d(TextureFormat::RED, TextureFormat::RED, + m_text_texture->tex_image_3d(TextureFormat::R8, TextureFormat::RED, GL_UNSIGNED_BYTE, nullptr, m_texture_width, m_texture_height, MAX_CHARACTER); @@ -59,7 +59,7 @@ void Font::setup_font_character() { load_character(c); } m_text_texture->set_linear(); - m_text_texture->set_repeat(false, true, true); + m_text_texture->set_clamp_to_edge(false, true, true); } std::vector Font::vertices(const std::string& text) {