diff --git a/openVulkanoCpp/Scene/TextDrawable.cpp b/openVulkanoCpp/Scene/TextDrawable.cpp index 036e199..5619114 100644 --- a/openVulkanoCpp/Scene/TextDrawable.cpp +++ b/openVulkanoCpp/Scene/TextDrawable.cpp @@ -126,9 +126,22 @@ namespace OpenVulkano::Scene m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT; } + uint32_t TextDrawable::GetFallbackGlyph() const + { + if (m_atlasData->glyphs.find(MISSING_GLYPH_SYMBOL) != m_atlasData->glyphs.end()) + { + return MISSING_GLYPH_SYMBOL; + } + Logger::RENDER->warn("Could not find glyph for character ? to use as fallback. Using first glyph instead"); + return m_atlasData->glyphs.begin()->first; + } + + void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos) { if (text.empty()) return; + if (!m_atlasData && !*m_atlasData) { Logger::RENDER->error("Must have glyphs"); return;} + const uint32_t fallbackGlyph = GetFallbackGlyph(); m_text = text; @@ -161,16 +174,8 @@ namespace OpenVulkano::Scene if (symbols->find(c) == symbols->end()) { - Logger::RENDER->error("Could not find glyph for character {}", c); - if (symbols->find(static_cast('?')) != symbols->end()) - { - c = static_cast('?'); - } - else - { - Logger::RENDER->error("Could not find glyph for character ? to replace glyph {}", c); - continue; - } + Logger::RENDER->warn("Could not find glyph for character {}, using fallback", c); + c = fallbackGlyph; } uint32_t vIdx = i * 4; diff --git a/openVulkanoCpp/Scene/TextDrawable.hpp b/openVulkanoCpp/Scene/TextDrawable.hpp index 134ba2e..2554899 100644 --- a/openVulkanoCpp/Scene/TextDrawable.hpp +++ b/openVulkanoCpp/Scene/TextDrawable.hpp @@ -34,6 +34,16 @@ namespace OpenVulkano::Scene { static Shader DEFAULT_SHADER_BITMAP, DEFAULT_SHADER_SDF, DEFAULT_SHADER_MSDF; + Geometry m_geometry; + Material m_material; + UniformBuffer m_uniBuffer; + std::shared_ptr m_atlasData; + Math::AABB m_bbox; + std::string m_text; + TextConfig m_cfg; + + uint32_t GetFallbackGlyph() const; + public: [[nodiscard]] static Shader& GetSdfDefaultShader() { return DEFAULT_SHADER_SDF; } [[nodiscard]] static Shader& GetMsdfDefaultShader() { return DEFAULT_SHADER_MSDF; } @@ -51,14 +61,5 @@ namespace OpenVulkano::Scene [[nodiscard]] TextConfig& GetConfig() { return m_cfg; } [[nodiscard]] const std::string& GetText() const { return m_text; } [[nodiscard]] const std::shared_ptr GetAtlasData() { return m_atlasData; } - - private: - Geometry m_geometry; - Material m_material; - UniformBuffer m_uniBuffer; - std::shared_ptr m_atlasData; - Math::AABB m_bbox; - std::string m_text; - TextConfig m_cfg; }; }