make font atlas generator interface more uniform and implement bitmap font atlas rendering and generation
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "Image/ImageLoaderPng.hpp"
|
||||
#include "Scene/FontAtlasGenerator.hpp"
|
||||
#include "Scene/IFontAtlasGenerator.hpp"
|
||||
#include "Scene/BitmapFontAtlasGenerator.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -39,6 +40,7 @@ namespace OpenVulkano
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
//#define CREATE_NEW_ATLAS 1
|
||||
#define CREATE_BITMAP_ATLAS 0
|
||||
|
||||
class TextExampleAppImpl final : public TextExampleApp
|
||||
{
|
||||
@@ -66,21 +68,34 @@ namespace OpenVulkano
|
||||
const int N = texts.size();
|
||||
auto& resourceLoader = ResourceLoader::GetInstance();
|
||||
const std::string fontPath = resourceLoader.GetResourcePath("Roboto-Regular.ttf");
|
||||
m_nodesPool.resize(N * 2);
|
||||
m_drawablesPool.resize(N * 2);
|
||||
|
||||
m_nodesPool.resize(N * 3);
|
||||
m_drawablesPool.resize(N * 3);
|
||||
|
||||
#if CREATE_BITMAP_ATLAS
|
||||
std::set<uint32_t> s = BitmapFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||
BitmapFontAtlasGenerator generator;
|
||||
generator.GenerateAtlas(fontPath, s);
|
||||
generator.SaveAtlasMetadataInfo("bitmap_atlas");
|
||||
#endif
|
||||
|
||||
#if defined(MSDFGEN_AVAILABLE) && defined(CREATE_NEW_ATLAS)
|
||||
msdf_atlas::Charset charset = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||
m_atlasGenerator.GenerateAtlas(fontPath, charset);
|
||||
m_msdfAtlasGenerator.GenerateAtlas(fontPath, charset);
|
||||
m_atlasGenerator.SaveAtlasMetadataInfo("sdf_atlas.png");
|
||||
m_msdfAtlasGenerator.SaveAtlasMetadataInfo("msdf_atlas");
|
||||
std::set<uint32_t> s = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||
msdf_atlas::Charset charset;
|
||||
for (uint32_t c : s)
|
||||
{
|
||||
charset.add(c);
|
||||
}
|
||||
m_atlasGenerator.GenerateAtlas(fontPath, charset);
|
||||
m_msdfAtlasGenerator.GenerateAtlas(fontPath, charset);
|
||||
m_atlasGenerator.SaveAtlasMetadataInfo("sdf_atlas.png");
|
||||
m_msdfAtlasGenerator.SaveAtlasMetadataInfo("msdf_atlas");
|
||||
#else
|
||||
auto sdfMetadataInfo = resourceLoader.GetResource("sdf_atlas_packed.png");
|
||||
auto msdfMetadataInfo = resourceLoader.GetResource("msdf_atlas_packed.png");
|
||||
auto bitmapMetadataInfo = resourceLoader.GetResource("bitmap_atlas_packed.png");
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < texts.size() * 2; i++)
|
||||
for (int i = 0; i < texts.size() * 3; i++)
|
||||
{
|
||||
int textIdx = i % texts.size();
|
||||
TextDrawable* t = nullptr;
|
||||
@@ -96,15 +111,24 @@ namespace OpenVulkano
|
||||
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
|
||||
}
|
||||
#else
|
||||
if (i < texts.size())
|
||||
int xOffset = 0;
|
||||
if (i < N)
|
||||
{
|
||||
t = new TextDrawable(sdfMetadataInfo, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetSdfDefaultShader());
|
||||
xOffset = -5;
|
||||
}
|
||||
else
|
||||
else if (i >= N && i < N * 2)
|
||||
{
|
||||
t = new TextDrawable(msdfMetadataInfo, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
|
||||
xOffset = 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = new TextDrawable(bitmapMetadataInfo, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetBitmapDefaultShader());
|
||||
xOffset = 35;
|
||||
}
|
||||
// OR use separate texture + metadata file
|
||||
//auto metadataInfo = resourceLoader.GetResource("atlas_metadata");
|
||||
@@ -121,7 +145,7 @@ namespace OpenVulkano
|
||||
t->GenerateText(texts[textIdx].first);
|
||||
m_drawablesPool[i] = t;
|
||||
m_nodesPool[i].Init();
|
||||
m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f((i < texts.size() ? -5 : 15), 2 - textIdx * 2, 0)));
|
||||
m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f(xOffset, 2 - textIdx * 2, 0)));
|
||||
m_nodesPool[i].AddDrawable(m_drawablesPool[i]);
|
||||
m_scene.GetRoot()->AddChild(&m_nodesPool[i]);
|
||||
}
|
||||
|
||||
BIN
examples/ExampleSources/bitmap_atlas_packed.png
Normal file
BIN
examples/ExampleSources/bitmap_atlas_packed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 KiB |
Reference in New Issue
Block a user