text with smallest possible spacing between glyphs

This commit is contained in:
ohyzha
2025-01-22 17:08:14 +02:00
parent 8ebf3aa7d2
commit a73df1b4f3
2 changed files with 26 additions and 17 deletions

View File

@@ -34,7 +34,7 @@ namespace OpenVulkano
namespace fs = std::filesystem;
constexpr int CREATE_BITMAP_ATLAS = 0;
constexpr int CREATE_NEW_ATLAS = 0;
//#define CREATE_NEW_ATLAS
class TextExampleAppImpl final : public TextExampleApp
{
@@ -53,6 +53,8 @@ namespace OpenVulkano
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("Unsupported glyphs \u1E30\u1E31 are coming", TextConfig()));
texts.push_back(std::make_pair("AAAA, ____", TextConfig()));
texts.push_back(std::make_pair("0123456789", TextConfig()));
texts.push_back(std::make_pair("This is first line\nSecond gg line\nThird G line", TextConfig()));
texts[1].second.backgroundColor.a = 255;
@@ -72,12 +74,12 @@ namespace OpenVulkano
generator.GetAtlas()->Save("bitmap_atlas_packed.png");
}
#if defined(MSDFGEN_AVAILABLE) && CREATE_NEW_ATLAS
std::set<uint32_t> s = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
m_atlasGenerator.GenerateAtlas(fontPath, s);
m_msdfAtlasGenerator.GenerateAtlas(fontPath, s);
m_atlasGenerator.GetAtlas()->Save("sdf_atlas_packed.png");
m_msdfAtlasGenerator.GetAtlas()->Save("msdf_atlas_packed.png");
#if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS)
std::set<uint32_t> s = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
m_atlasGenerator.GenerateAtlas(fontPath, s);
m_msdfAtlasGenerator.GenerateAtlas(fontPath, s);
m_atlasGenerator.GetAtlas()->Save("sdf_atlas_packed.png");
m_msdfAtlasGenerator.GetAtlas()->Save("msdf_atlas_packed.png");
#else
auto sdfMetadataInfo = resourceLoader.GetResource("sdf_atlas_packed.png");
auto msdfMetadataInfo = resourceLoader.GetResource("msdf_atlas_packed.png");
@@ -90,16 +92,14 @@ namespace OpenVulkano
for (int j = 0; j < texts.size(); j++)
{
TextDrawable* t = nullptr;
#if defined(MSDFGEN_AVAILABLE) && CREATE_NEW_ATLAS
#if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS)
if (i < texts.size())
{
t = new TextDrawable(m_atlasGenerator.GetAtlasData(), texts[j].second);
t->SetShader(&TextDrawable::GetSdfDefaultShader());
t = new TextDrawable(m_atlasGenerator.GetAtlas(), texts[j].second);
}
else
{
t = new TextDrawable(m_msdfAtlasGenerator.GetAtlasData(), texts[j].second);
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
t = new TextDrawable(m_msdfAtlasGenerator.GetAtlas(), texts[j].second);
}
#else
if (i == 0)