diff --git a/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp b/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp index 6d11046..2716975 100644 --- a/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp +++ b/openVulkanoCpp/Scene/SdfFontAtlasGenerator.cpp @@ -111,7 +111,7 @@ namespace OpenVulkano::Scene template void SdfFontAtlasGeneratorGeneric::Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset, - const std::optional& pngOutput) + const std::optional& pngOutput) { std::vector glyphsGeometry; // FontGeometry is a helper class that loads a set of glyphs from a single font. @@ -122,7 +122,9 @@ namespace OpenVulkano::Scene { const double maxCornerAngle = 3.0; for (msdf_atlas::GlyphGeometry& glyph : glyphsGeometry) + { glyph.edgeColoring(&msdfgen::edgeColoringByDistance, maxCornerAngle, 0); + } } msdf_atlas::TightAtlasPacker packer; @@ -147,8 +149,10 @@ namespace OpenVulkano::Scene generator.generate(glyphsGeometry.data(), glyphsGeometry.size()); int idx = 0; - m_atlasData = std::make_shared(Math::Vector2ui{ width, height }, fontGeometry.getMetrics().lineHeight, - channelsCount == 1 ? FontAtlasType::SDF : FontAtlasType::MSDF, m_channelsCount == 1 ? DataFormat::R8_UNORM : DataFormat::R8G8B8A8_UNORM); + m_atlasData = + std::make_shared(Math::Vector2ui { width, height }, fontGeometry.getMetrics().lineHeight, + channelsCount == 1 ? FontAtlasType::SDF : FontAtlasType::MSDF, + m_channelsCount == 1 ? DataFormat::R8_UNORM : DataFormat::R8G8B8A8_UNORM); if constexpr (Channels == 3) { @@ -164,7 +168,7 @@ namespace OpenVulkano::Scene } } else - { + { const msdfgen::BitmapConstRef& storage = generator.atlasStorage(); memcpy(m_atlasData->GetTexture()->textureBuffer, storage.pixels, width * height); } @@ -174,7 +178,7 @@ namespace OpenVulkano::Scene double l = 0, r = 0, t = 0, b = 0; }; - for (const auto& glyph: glyphsGeometry) + for (const auto& glyph : glyphsGeometry) { GlyphInfo& info = m_atlasData->GetGlyphs()[glyph.getCodepoint()]; const msdf_atlas::GlyphBox& glyphBox = generator.getLayout()[idx++]; @@ -187,6 +191,8 @@ namespace OpenVulkano::Scene double bearingY = glyphBox.bounds.t; double w = glyphBaselineBbox.r - glyphBaselineBbox.l; double h = glyphBaselineBbox.t - glyphBaselineBbox.b; + + // UV mapping double l = glyphAtlasBbox.l; double r = glyphAtlasBbox.r; double t = glyphAtlasBbox.t; @@ -200,7 +206,10 @@ namespace OpenVulkano::Scene SetGlyphData(info, { bearingX, bearingY }, { w, h }, glyphAtlasAABB, glyphBox.advance); } - if (pngOutput && !pngOutput->empty()) { m_atlasData->Save(*pngOutput); } + if (pngOutput && !pngOutput->empty()) + { + m_atlasData->Save(*pngOutput); + } destroyFont(font); deinitializeFreetype(ft); } @@ -208,4 +217,4 @@ namespace OpenVulkano::Scene template class SdfFontAtlasGeneratorGeneric<1>; template class SdfFontAtlasGeneratorGeneric<3>; } -#endif \ No newline at end of file +#endif