implement text rendering without msdfgen library

This commit is contained in:
ohyzha
2024-08-05 18:25:19 +03:00
parent 62a0e84634
commit afccf5dee0
10 changed files with 302 additions and 150 deletions

View File

@@ -62,7 +62,6 @@ namespace OpenVulkano
const int N = texts.size();
auto& resourceLoader = ResourceLoader::GetInstance();
const std::string fontPath = resourceLoader.GetResourcePath("Roboto-Regular.ttf");
const std::string atlasPath = (fs::path(fontPath).parent_path() / "roboto-regular-atlas.png").string();
m_nodesPool.resize(N);
m_drawablesPool.resize(N);
@@ -72,11 +71,28 @@ namespace OpenVulkano
// some unicode values
charset.add(c);
}
#ifdef MSDFGEN_AVAILABLE
m_atlasGenerator.GenerateAtlas(fontPath, charset);
#endif
for (int i = 0; i < texts.size(); i++)
{
#ifdef MSDFGEN_AVAILABLE
TextDrawable* t = new TextDrawable(&m_atlasGenerator, texts[i].second);
#else
auto metadataInfoPath = resourceLoader.GetResourcePath("atlas_metadata");
auto data = resourceLoader.GetResource("roboto-regular-atlas.png");
auto metadataInfo = TextDrawable::ReadAtlasMetadataFile(metadataInfoPath);
Image::ImageLoaderPng loader;
static auto image = loader.loadData(reinterpret_cast<uint8_t*>(data.Data()), data.Size());
static Texture tex;
tex.resolution = image->resolution;
tex.textureBuffer = image->data.Data();
tex.format = image->dataFormat;
tex.size = image->data.Size(); // 1 channel
TextDrawable* t = new TextDrawable(metadataInfo, &tex, texts[i].second);
#endif // MSDFGEN_AVAILABLE
t->GenerateText(texts[i].first);
m_drawablesPool[i] = t;
m_nodesPool[i].Init();
@@ -113,7 +129,9 @@ namespace OpenVulkano
OpenVulkano::Scene::Scene m_scene;
PerspectiveCamera m_cam;
OpenVulkano::FreeCamCameraController m_camController;
#ifdef MSDFGEN_AVAILABLE
FontAtlasGenerator m_atlasGenerator;
#endif
std::vector<SimpleDrawable*> m_drawablesPool;
std::vector<Node> m_nodesPool;
Vector3f_SIMD m_position = { 0, 0, -10 };