render question mark if glyph is not loaded

This commit is contained in:
ohyzha
2024-08-08 12:23:38 +03:00
parent a390470420
commit 1659cee9eb
2 changed files with 44 additions and 36 deletions

View File

@@ -57,6 +57,7 @@ namespace OpenVulkano
texts.push_back(std::make_pair("ABab?.^{}_cdFGETG123)(", TextConfig())); texts.push_back(std::make_pair("ABab?.^{}_cdFGETG123)(", TextConfig()));
texts.push_back(std::make_pair("Hello, World!", 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("\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.push_back(std::make_pair("This is first line\nSecond gg line\nThird G line", TextConfig()));
texts[0].second.applyBorder = true; texts[0].second.applyBorder = true;
texts[1].second.backgroundColor.a = 1; texts[1].second.backgroundColor.a = 1;

View File

@@ -170,45 +170,52 @@ namespace OpenVulkano::Scene
cursorX = pos.x; cursorX = pos.x;
continue; 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); Logger::RENDER->error("Could not find glyph for character {}", c);
if (symbols->find(static_cast<uint32_t>('?')) != symbols->end())
{
c = static_cast<uint32_t>('?');
}
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); SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer);
} }