Merge remote-tracking branch 'origin/master' into project_setup_refactor
# Conflicts: # CMakeLists.txt
This commit is contained in:
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.28 FATAL_ERROR)
|
||||
|
||||
include(SetupVulkan)
|
||||
include(Utils)
|
||||
include(CopyResourcesToExe)
|
||||
|
||||
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/ExampleApps/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
|
||||
if (IOS)
|
||||
@@ -33,7 +34,8 @@ if(APPLE)
|
||||
LinkAppleFrameworks(OpenVulkano_Examples)
|
||||
endif ()
|
||||
|
||||
|
||||
CopyResourcesToExe(openVulkanoCpp "${CMAKE_CURRENT_SOURCE_DIR}/../fonts" ".ttf")
|
||||
CopyResourcesToExe(openVulkanoCpp "${CMAKE_CURRENT_SOURCE_DIR}/ExampleSources" "*")
|
||||
|
||||
target_include_directories(OpenVulkano_Examples PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(OpenVulkano_Examples PRIVATE openVulkanoCpp)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "ExampleApps/MovingCubeApp.hpp"
|
||||
#include "ExampleApps/TexturedCubeExampleApp.hpp"
|
||||
#include "ExampleApps/BillboardExampleApp.hpp"
|
||||
#include "ExampleApps/TextExampleApp.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace OpenVulkano
|
||||
@@ -18,6 +19,7 @@ namespace OpenVulkano
|
||||
{ "Cubes Example App", &CubesExampleApp::Create },
|
||||
{ "Moving Cube Example App", &MovingCubeApp::Create },
|
||||
{ "Textured Cube Example App", &TexturedCubeExampleApp::Create },
|
||||
{ "Billboard Example App", &BillboardExampleApp::Create }
|
||||
{ "Billboard Example App", &BillboardExampleApp::Create },
|
||||
{ "Text Example App", &TextExampleApp::Create }
|
||||
};
|
||||
}
|
||||
|
||||
176
examples/ExampleApps/TextExampleApp.cpp
Normal file
176
examples/ExampleApps/TextExampleApp.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "TextExampleApp.hpp"
|
||||
#include "Scene/Scene.hpp"
|
||||
#include "Scene/Shader/Shader.hpp"
|
||||
#include "Scene/Geometry.hpp"
|
||||
#include "Scene/TextDrawable.hpp"
|
||||
#include "Scene/GeometryFactory.hpp"
|
||||
#include "Scene/Material.hpp"
|
||||
#include "Scene/Vertex.hpp"
|
||||
#include "Scene/SimpleDrawable.hpp"
|
||||
#include "Scene/UI/PerformanceInfo.hpp"
|
||||
#include "Scene/UniformBuffer.hpp"
|
||||
#include "Input/InputManager.hpp"
|
||||
#include "Host/GraphicsAppManager.hpp"
|
||||
#include "Host/GLFW/WindowGLFW.hpp"
|
||||
#include "Host/ResourceLoader.hpp"
|
||||
#include "Math/Math.hpp"
|
||||
#include "Base/EngineConfiguration.hpp"
|
||||
#include "Controller/FreeCamCameraController.hpp"
|
||||
#include "Image/ImageLoaderPng.hpp"
|
||||
#include "Scene/FontAtlasGenerator.hpp"
|
||||
#include "Scene/IFontAtlasGenerator.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
#undef TRANSPARENT
|
||||
#endif
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
using namespace Scene;
|
||||
using namespace Input;
|
||||
using namespace Math;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
class TextExampleAppImpl final : public TextExampleApp
|
||||
{
|
||||
public:
|
||||
|
||||
void Init() override
|
||||
{
|
||||
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
||||
engineConfig->SetNumThreads(4);
|
||||
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
||||
|
||||
std::srand(1); // Fix seed for random numbers
|
||||
m_scene.Init();
|
||||
m_cam.Init(70, 16, 9, 0.1f, 100);
|
||||
m_scene.SetCamera(&m_cam);
|
||||
|
||||
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.push_back(std::make_pair("Unsupported glyphs \u1E30\u1E31 are coming", TextConfig()));
|
||||
texts.push_back(std::make_pair("This is first line\nSecond gg line\nThird G line", TextConfig()));
|
||||
texts[0].second.applyBorder = true;
|
||||
texts[1].second.backgroundColor.a = 1;
|
||||
|
||||
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);
|
||||
|
||||
#ifdef MSDFGEN_AVAILABLE
|
||||
msdf_atlas::Charset charset = SdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||
m_atlasGenerator.GenerateAtlas(fontPath, charset);
|
||||
m_msdfAtlasGenerator.GenerateAtlas(fontPath, charset);
|
||||
#else
|
||||
auto sdfMetadataInfo = resourceLoader.GetResource("sdf_atlas_packed");
|
||||
auto msdfMetadataInfo = resourceLoader.GetResource("msdf_atlas_packed.png");
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < texts.size() * 2; i++)
|
||||
{
|
||||
int textIdx = i % texts.size();
|
||||
TextDrawable* t = nullptr;
|
||||
#ifdef MSDFGEN_AVAILABLE
|
||||
if (i < texts.size())
|
||||
{
|
||||
t = new TextDrawable(&m_atlasGenerator, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetSdfDefaultShader());
|
||||
}
|
||||
else
|
||||
{
|
||||
t = new TextDrawable(&m_msdfAtlasGenerator, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
|
||||
}
|
||||
#else
|
||||
if (i < texts.size())
|
||||
{
|
||||
t = new TextDrawable(sdfMetadataInfo, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetSdfDefaultShader());
|
||||
}
|
||||
else
|
||||
{
|
||||
t = new TextDrawable(msdfMetadataInfo, texts[textIdx].second);
|
||||
t->SetShader(&TextDrawable::GetMsdfDefaultShader());
|
||||
}
|
||||
// OR use separate texture + metadata file
|
||||
//auto metadataInfo = resourceLoader.GetResource("atlas_metadata");
|
||||
//auto data = resourceLoader.GetResource("roboto-regular-atlas.png");
|
||||
//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[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].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({ 10, 0, 15 });
|
||||
m_camController.SetBoostFactor(5);
|
||||
|
||||
std::shared_ptr<OpenVulkano::Scene::UI::PerformanceInfo> m_perfInfo =
|
||||
std::make_shared<OpenVulkano::Scene::UI::PerformanceInfo>();
|
||||
m_ui.AddElement(m_perfInfo);
|
||||
GetGraphicsAppManager()->GetRenderer()->SetActiveUi(&m_ui);
|
||||
}
|
||||
|
||||
void Tick() override
|
||||
{
|
||||
m_camController.Tick();
|
||||
}
|
||||
|
||||
void Close() override
|
||||
{
|
||||
for (SimpleDrawable* d: m_drawablesPool)
|
||||
{
|
||||
d->Close();
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
OpenVulkano::Scene::Scene m_scene;
|
||||
PerspectiveCamera m_cam;
|
||||
OpenVulkano::FreeCamCameraController m_camController;
|
||||
#ifdef MSDFGEN_AVAILABLE
|
||||
SdfFontAtlasGenerator m_atlasGenerator;
|
||||
MsdfFontAtlasGenerator m_msdfAtlasGenerator;
|
||||
#endif
|
||||
std::vector<SimpleDrawable*> m_drawablesPool;
|
||||
std::vector<Node> m_nodesPool;
|
||||
Vector3f_SIMD m_position = { 0, 0, -10 };
|
||||
OpenVulkano::Scene::UI::SimpleUi m_ui;
|
||||
std::shared_ptr<OpenVulkano::Scene::UI::PerformanceInfo> m_perfInfo;
|
||||
};
|
||||
|
||||
IGraphicsApp* TextExampleApp::Create() { return new TextExampleAppImpl(); }
|
||||
|
||||
std::unique_ptr<IGraphicsApp> TextExampleApp::CreateUnique()
|
||||
{
|
||||
return std::make_unique<TextExampleAppImpl>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma clang diagnostic pop
|
||||
27
examples/ExampleApps/TextExampleApp.hpp
Normal file
27
examples/ExampleApps/TextExampleApp.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Base/IGraphicsApp.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
class TextExampleApp : public IGraphicsApp
|
||||
{
|
||||
public:
|
||||
static IGraphicsApp* Create();
|
||||
|
||||
static std::unique_ptr<IGraphicsApp> CreateUnique();
|
||||
|
||||
[[nodiscard]] std::string GetAppName() const final
|
||||
{ return "Text ExampleApp"; }
|
||||
|
||||
[[nodiscard]] OpenVulkano::Version GetAppVersion() const final
|
||||
{ return {"v1.0"}; }
|
||||
};
|
||||
}
|
||||
BIN
examples/ExampleSources/msdf_atlas_packed.png
Normal file
BIN
examples/ExampleSources/msdf_atlas_packed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1012 KiB |
BIN
examples/ExampleSources/sdf_atlas_packed
Normal file
BIN
examples/ExampleSources/sdf_atlas_packed
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 449 KiB |
Reference in New Issue
Block a user