From 1659cee9eb0d869bff0bdc5bcf12f7a95b0b2b2f Mon Sep 17 00:00:00 2001 From: ohyzha Date: Thu, 8 Aug 2024 12:23:38 +0300 Subject: [PATCH] render question mark if glyph is not loaded --- examples/ExampleApps/TextExampleApp.cpp | 1 + openVulkanoCpp/Scene/TextDrawable.cpp | 79 ++++++++++++++----------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/examples/ExampleApps/TextExampleApp.cpp b/examples/ExampleApps/TextExampleApp.cpp index 5671ec4..1df7521 100644 --- a/examples/ExampleApps/TextExampleApp.cpp +++ b/examples/ExampleApps/TextExampleApp.cpp @@ -57,6 +57,7 @@ namespace OpenVulkano texts.push_back(std::make_pair("ABab?.^{}_cdFGETG123)(", TextConfig())); texts.push_back(std::make_pair("Hello, World!", TextConfig())); texts.push_back(std::make_pair("\u0410\u0411\u0412\u041F", TextConfig())); + texts.push_back(std::make_pair("Text with unsupported glyphs \u1E30\u1E31 is coming", TextConfig())); texts.push_back(std::make_pair("This is first line\nSecond gg line\nThird G line", TextConfig())); texts[0].second.applyBorder = true; texts[1].second.backgroundColor.a = 1; diff --git a/openVulkanoCpp/Scene/TextDrawable.cpp b/openVulkanoCpp/Scene/TextDrawable.cpp index 386bbf2..3a3fce4 100644 --- a/openVulkanoCpp/Scene/TextDrawable.cpp +++ b/openVulkanoCpp/Scene/TextDrawable.cpp @@ -170,45 +170,52 @@ namespace OpenVulkano::Scene cursorX = pos.x; continue; } - if (symbols->find(c) != symbols->end()) + + if (symbols->find(c) == symbols->end()) { - uint32_t vIdx = i * 4; - uint32_t indices[] = { 1 + vIdx, 2 + vIdx, 3 + vIdx, 1 + vIdx, 3 + vIdx, 0 + vIdx }; - GlyphInfo& info = symbols->at(c); - - // left bottom - m_geometry.vertices[vIdx].position.x = info.xyz[0].x + cursorX; - m_geometry.vertices[vIdx].position.y = posY - info.xyz[0].y; - m_geometry.vertices[vIdx].position.z = info.xyz[0].z; - m_geometry.vertices[vIdx].textureCoordinates = Math::Vector3f(info.uv[0], 0); - - // right bottom - m_geometry.vertices[vIdx + 1].position.x = info.xyz[1].x + cursorX; - m_geometry.vertices[vIdx + 1].position.y = posY - info.xyz[1].y; - m_geometry.vertices[vIdx + 1].position.z = info.xyz[1].z; - m_geometry.vertices[vIdx + 1].textureCoordinates = Math::Vector3f(info.uv[1], 0); - - // top right - m_geometry.vertices[vIdx + 2].position.x = info.xyz[2].x + cursorX; - m_geometry.vertices[vIdx + 2].position.y = posY + info.xyz[2].y; - m_geometry.vertices[vIdx + 2].position.z = info.xyz[2].z; - m_geometry.vertices[vIdx + 2].textureCoordinates = Math::Vector3f(info.uv[2], 0); - - // top left - m_geometry.vertices[vIdx + 3].position.x = info.xyz[3].x + cursorX; - m_geometry.vertices[vIdx + 3].position.y = posY + info.xyz[3].y; - m_geometry.vertices[vIdx + 3].position.z = info.xyz[3].z; - m_geometry.vertices[vIdx + 3].textureCoordinates = Math::Vector3f(info.uv[3], 0); - m_geometry.SetIndices(indices, 6, 6 * i); - // TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols - // when setting for depth comparison operator will be available( <= ) - cursorX += info.advance + 0.08; - } - else - { - // throw ? replace with ? character (if available) ? 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; + } } + + uint32_t vIdx = i * 4; + uint32_t indices[] = { 1 + vIdx, 2 + vIdx, 3 + vIdx, 1 + vIdx, 3 + vIdx, 0 + vIdx }; + GlyphInfo& info = symbols->at(c); + + // left bottom + m_geometry.vertices[vIdx].position.x = info.xyz[0].x + cursorX; + m_geometry.vertices[vIdx].position.y = posY - info.xyz[0].y; + m_geometry.vertices[vIdx].position.z = info.xyz[0].z; + m_geometry.vertices[vIdx].textureCoordinates = Math::Vector3f(info.uv[0], 0); + + // right bottom + m_geometry.vertices[vIdx + 1].position.x = info.xyz[1].x + cursorX; + m_geometry.vertices[vIdx + 1].position.y = posY - info.xyz[1].y; + m_geometry.vertices[vIdx + 1].position.z = info.xyz[1].z; + m_geometry.vertices[vIdx + 1].textureCoordinates = Math::Vector3f(info.uv[1], 0); + + // top right + m_geometry.vertices[vIdx + 2].position.x = info.xyz[2].x + cursorX; + m_geometry.vertices[vIdx + 2].position.y = posY + info.xyz[2].y; + m_geometry.vertices[vIdx + 2].position.z = info.xyz[2].z; + m_geometry.vertices[vIdx + 2].textureCoordinates = Math::Vector3f(info.uv[2], 0); + + // top left + m_geometry.vertices[vIdx + 3].position.x = info.xyz[3].x + cursorX; + m_geometry.vertices[vIdx + 3].position.y = posY + info.xyz[3].y; + m_geometry.vertices[vIdx + 3].position.z = info.xyz[3].z; + m_geometry.vertices[vIdx + 3].textureCoordinates = Math::Vector3f(info.uv[3], 0); + m_geometry.SetIndices(indices, 6, 6 * i); + // TODO: change to lower value(or ideally remove completely) to avoid overlapping and make less space between symbols + // when setting for depth comparison operator will be available( <= ) + cursorX += info.advance + 0.08; } SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer); }