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

52 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, 0 }; // vec4 to match paddding (multiple of 16)
Math::Vector3f borderColor = { 1, 0, 0 };
float threshold = 0.4f;
float borderSize = 0.05f;
float smoothing = 1.f/32.f;
bool applyBorder = false;
//bool sdfMultiChannel = false;
};
class Text : public SimpleDrawable
{
public:
Text() = default;
~Text();
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;
};
}