implement label drawable
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "ExampleApps/TexturedCubeExampleApp.hpp"
|
||||
#include "ExampleApps/BillboardExampleApp.hpp"
|
||||
#include "ExampleApps/TextExampleApp.hpp"
|
||||
#include "ExampleApps/LabelDrawableExampleApp.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace OpenVulkano
|
||||
@@ -20,6 +21,7 @@ namespace OpenVulkano
|
||||
{ "Moving Cube Example App", &MovingCubeApp::Create },
|
||||
{ "Textured Cube Example App", &TexturedCubeExampleApp::Create },
|
||||
{ "Billboard Example App", &BillboardExampleApp::Create },
|
||||
{ "Text Example App", &TextExampleApp::Create }
|
||||
{ "Text Example App", &TextExampleApp::Create },
|
||||
{ "Label Example App", &LabelDrawableExampleApp::Create }
|
||||
};
|
||||
}
|
||||
|
||||
133
examples/ExampleApps/LabelDrawableExampleApp.cpp
Normal file
133
examples/ExampleApps/LabelDrawableExampleApp.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 "LabelDrawableExampleApp.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 "Scene/Prefabs/LabelDrawable.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 LabelDrawableExampleAppImpl final : public LabelDrawableExampleApp
|
||||
{
|
||||
public:
|
||||
|
||||
void Init() override
|
||||
{
|
||||
auto engineConfig = OpenVulkano::EngineConfiguration::GetEngineConfiguration();
|
||||
engineConfig->SetNumThreads(1);
|
||||
engineConfig->SetPreferFramebufferFormatSRGB(false);
|
||||
|
||||
std::srand(1); // Fix seed for random numbers
|
||||
m_scene.Init();
|
||||
m_cam.Init(70, 16, 9, 0.1, 100);
|
||||
m_scene.SetCamera(&m_cam);
|
||||
|
||||
auto& resourceLoader = ResourceLoader::GetInstance();
|
||||
auto sdfMetadataInfo = resourceLoader.GetResource("sdf_atlas_packed.png");
|
||||
|
||||
const int N = 3;
|
||||
m_nodesPool.resize(N);
|
||||
m_drawablesPool.reserve(N);
|
||||
|
||||
static TextDrawable textDrawable(sdfMetadataInfo);
|
||||
auto& sh = TextDrawable::GetSdfDefaultShader();
|
||||
sh.depthWrite = false;
|
||||
sh.depthCompareOp = CompareOp::LESS_OR_EQUAL;
|
||||
textDrawable.SetShader(&sh);
|
||||
const std::vector<std::string> texts = { "Hello", "1", "XYZ" };
|
||||
BillboardControlBlock billboardSettings;
|
||||
LabelDrawableSettings labelSettings;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
//labelSettings.hasRoundedCorners = (i % 2 == 0 ? 1 : 0);
|
||||
labelSettings.hasArrow = (i % 2 == 0 ? 1 : 0);
|
||||
bool isBillboard = (i % 2 == 0 ? 1 : 0);
|
||||
LabelDrawable& label = m_drawablesPool.emplace_back(labelSettings, isBillboard);
|
||||
label.SetBillboardSettings(billboardSettings);
|
||||
label.AddText(&textDrawable, texts[i]);
|
||||
if (i == 2)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
label.AddText(&textDrawable, "Additional text" + std::to_string(j));
|
||||
}
|
||||
}
|
||||
m_scene.GetRoot()->AddChild(&m_nodesPool[i]);
|
||||
m_nodesPool[i].SetMatrix(Math::Utils::translate(glm::mat4x4(1.f), Vector3f(-5 + std::rand() % 5, -5 + std::rand() % 5, -std::rand() % 10)));
|
||||
m_nodesPool[i].AddDrawable(&m_drawablesPool[i]);
|
||||
}
|
||||
|
||||
GetGraphicsAppManager()->GetRenderer()->SetScene(&m_scene);
|
||||
m_camController.Init(&m_cam);
|
||||
m_camController.SetDefaultKeybindings();
|
||||
m_camController.SetPosition({ 0, 0, 10 });
|
||||
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 Close() override {}
|
||||
|
||||
void Tick() override
|
||||
{
|
||||
m_camController.Tick();
|
||||
}
|
||||
|
||||
private:
|
||||
OpenVulkano::Scene::Scene m_scene;
|
||||
PerspectiveCamera m_cam;
|
||||
OpenVulkano::FreeCamCameraController m_camController;
|
||||
std::vector<LabelDrawable> 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* LabelDrawableExampleApp::Create() { return new LabelDrawableExampleAppImpl(); }
|
||||
|
||||
std::unique_ptr<IGraphicsApp> LabelDrawableExampleApp::CreateUnique()
|
||||
{
|
||||
return std::make_unique<LabelDrawableExampleAppImpl>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
#pragma clang diagnostic pop
|
||||
25
examples/ExampleApps/LabelDrawableExampleApp.hpp
Normal file
25
examples/ExampleApps/LabelDrawableExampleApp.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 LabelDrawableExampleApp : public IGraphicsApp
|
||||
{
|
||||
public:
|
||||
static IGraphicsApp* Create();
|
||||
|
||||
static std::unique_ptr<IGraphicsApp> CreateUnique();
|
||||
|
||||
[[nodiscard]] std::string GetAppName() const final { return "Label drawable ExampleApp"; }
|
||||
|
||||
[[nodiscard]] OpenVulkano::Version GetAppVersion() const final { return { "v1.0" }; }
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user