Files
OpenVulkano/openVulkanoCpp/Scene/TextDrawable.hpp
2024-08-06 10:32:55 +03:00

53 lines
1.5 KiB
C++

/*
* 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 "UpdateFrequency.hpp"
#include "Base/ICloseable.hpp"
#include "Math/Math.hpp"
#include "DataFormat.hpp"
#include "SimpleDrawable.hpp"
#include "FontAtlasGenerator.hpp"
#include "Texture.hpp"
#include "msdfgen.h"
#include "msdfgen-ext.h"
#include "msdf-atlas-gen/msdf-atlas-gen.h"
namespace OpenVulkano::Scene
{
using namespace msdfgen;
using namespace msdf_atlas;
struct TextConfig
{
Math::Vector4f textColor = { 1, 1, 1, 1 };
Math::Vector4f borderColor = { 1, 0, 0, 1 };
Math::Vector4f backgroundColor = { 0, 1, 0, 0 };
float threshold = 0.4f;
float borderSize = 0.05f;
float smoothing = 1.f/32.f;
uint32_t applyBorder = false;
//bool sdfMultiChannel = false;
};
class TextDrawable : public SimpleDrawable
{
public:
TextDrawable() = default;
~TextDrawable();
void SetUniformBuffer(UniformBuffer* buffer) { m_uniBuffer = buffer; }
void GenerateText(const std::string& text, const Math::Vector3f& pos = Math::Vector3f(0.f));
void SetConfig(const TextConfig& cfg) { m_cfg = cfg; }
TextConfig& GetConfig() { return m_cfg; }
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator) { m_fontAtlasGenerator = fontAtlasGenerator; }
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
private:
FontAtlasGenerator* m_fontAtlasGenerator = nullptr;
TextConfig m_cfg;
};
}