diff --git a/openVulkanoCpp/Scene/TextDrawable.cpp b/openVulkanoCpp/Scene/TextDrawable.cpp index 3a3fce4..cdad027 100644 --- a/openVulkanoCpp/Scene/TextDrawable.cpp +++ b/openVulkanoCpp/Scene/TextDrawable.cpp @@ -127,8 +127,23 @@ namespace OpenVulkano::Scene return; } + auto GetActualLength = [&]() + { + auto begin = text.begin(); + auto end = text.end(); + size_t len = 0; + while (begin != end) + { + uint32_t c = utf8::next(begin, end); + if (c == '\n') continue; + ++len; + } + return len; + }; + + size_t len = GetActualLength(); m_geometry.Close(); - m_geometry.Init(text.size() * 4, text.size() * 6); + m_geometry.Init(len * 4, len * 6); // TODO: better implementation to decide what to use: data from atlas generator or data read from file // we have msdf but loaded glyphs metadata from file before @@ -161,7 +176,8 @@ namespace OpenVulkano::Scene auto end = text.end(); const double lineHeight = meta->lineHeight; double posY = pos.y; - for (size_t i = 0; begin != end; i++) + int i = 0; + while (begin != end) { uint32_t c = utf8::next(begin, end); if (c == '\n') @@ -216,6 +232,7 @@ namespace OpenVulkano::Scene // 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; + ++i; } SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer); }