refactor code and support utf8 strings rendering

This commit is contained in:
ohyzha
2024-08-02 23:08:24 +03:00
parent 875ad80337
commit 9589b4d39f
11 changed files with 70 additions and 30 deletions

View File

@@ -8,7 +8,7 @@
#include "Scene/Scene.hpp"
#include "Scene/Shader/Shader.hpp"
#include "Scene/Geometry.hpp"
#include "Scene/Text.hpp"
#include "Scene/TextDrawable.hpp"
#include "Scene/GeometryFactory.hpp"
#include "Scene/Material.hpp"
#include "Scene/Vertex.hpp"
@@ -55,13 +55,13 @@ namespace OpenVulkano
static std::vector<std::pair<std::string, TextConfig>> texts;
texts.push_back(std::make_pair("ABab?.^{}_cdFGETG123)(", TextConfig()));
texts.push_back(std::make_pair("Hello, World!", TextConfig()));
texts.push_back(std::make_pair("\u0410\u0411\u0412\u041F", TextConfig()));
texts[0].second.applyBorder = true;
texts[1].second.backgroundColor.a = 1;
const int N = texts.size();
std::string fontPath;
auto& resourceLoader = ResourceLoader::GetInstance();
resourceLoader.GetResource("Roboto-Regular.ttf", fontPath);
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);
@@ -81,11 +81,17 @@ namespace OpenVulkano
m_shader.alphaBlend = true;
m_shader.cullMode = CullMode::NONE;
m_atlasGenerator.GenerateAtlas(fontPath, atlasPath);
Charset charset = Charset::ASCII;
for (unicode_t c = 0x0410; c <= 0x041F; c++)
{
// some unicode values
charset.add(c);
}
m_atlasGenerator.GenerateAtlas(fontPath, atlasPath, charset);
for (int i = 0; i < texts.size(); i++)
{
Text* t = new Text();
TextDrawable* t = new TextDrawable();
t->SetFontAtlasGenerator(&m_atlasGenerator);
t->SetConfig(texts[i].second);
t->SetUniformBuffer(&m_uniBuffers[i]);
@@ -93,15 +99,14 @@ namespace OpenVulkano
t->GenerateText(texts[i].first);
m_drawablesPool[i] = t;
m_nodesPool[i].Init();
m_nodesPool[i].SetMatrix(
Math::Utils::translate(glm::mat4x4(1.f), Vector3f(-3 + std::rand() % 3, -2 + std::rand() % 4, 2)));
m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f(-5, 2 - i * 2, 0)));
m_nodesPool[i].AddDrawable(m_drawablesPool[i]);
m_scene.GetRoot()->AddChild(&m_nodesPool[i]);
}
GetGraphicsAppManager()->GetRenderer()->SetScene(&m_scene);
m_camController.Init(&m_cam);
m_camController.SetDefaultKeybindings();
m_camController.SetPosition({ 0, 0, 5 });
m_camController.SetPosition({ 0, 0, 10 });
m_camController.SetBoostFactor(5);
std::shared_ptr<OpenVulkano::Scene::UI::PerformanceInfo> m_perfInfo =