diff --git a/examples/ExampleApps/TextExampleApp.cpp b/examples/ExampleApps/TextExampleApp.cpp index acde656..5671ec4 100644 --- a/examples/ExampleApps/TextExampleApp.cpp +++ b/examples/ExampleApps/TextExampleApp.cpp @@ -68,7 +68,7 @@ namespace OpenVulkano m_drawablesPool.resize(N); #ifdef MSDFGEN_AVAILABLE - Charset charset = MsdfFontAtlasGenerator::LoadAllGlyphs(fontPath); + msdf_atlas::Charset charset = MsdfFontAtlasGenerator::LoadAllGlyphs(fontPath); //Charset charset = Charset::ASCII; //for (unicode_t c = 0x0410; c <= 0x041F; c++) //{ diff --git a/openVulkanoCpp/Scene/FontAtlasGenerator.hpp b/openVulkanoCpp/Scene/FontAtlasGenerator.hpp index cc05992..301dc9d 100644 --- a/openVulkanoCpp/Scene/FontAtlasGenerator.hpp +++ b/openVulkanoCpp/Scene/FontAtlasGenerator.hpp @@ -6,12 +6,12 @@ #pragma once +#include "Scene/AtlasMetadata.hpp" +#include "Scene/Texture.hpp" #include #include #include #include -#include "Scene/AtlasMetadata.hpp" -#include "Scene/Texture.hpp" #include #include diff --git a/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.cpp b/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.cpp index f4fbeea..59d24d9 100644 --- a/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.cpp +++ b/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.cpp @@ -9,9 +9,12 @@ #include "MsdfFontAtlasGenerator.hpp" #include "Base/Logger.hpp" #include "Scene/AtlasMetadata.hpp" +#include +#include +#include #define STBI_MSC_SECURE_CRT #define STB_IMAGE_WRITE_IMPLEMENTATION -#include "stb_image_write.h" +#include #include #include FT_FREETYPE_H #include @@ -255,7 +258,7 @@ namespace OpenVulkano::Scene deinitializeFreetype(ft); } - void MsdfFontAtlasGenerator::SavePng(const BitmapConstRef& storage, const std::string& output, + void MsdfFontAtlasGenerator::SavePng(const BitmapConstRef& storage, const std::string& output, int channels) const { stbi_flip_vertically_on_write(1); diff --git a/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.hpp b/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.hpp index 106f6a8..b094065 100644 --- a/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.hpp +++ b/openVulkanoCpp/Scene/MsdfFontAtlasGenerator.hpp @@ -8,48 +8,49 @@ #if __has_include("msdfgen.h") +#include "Scene/AtlasMetadata.hpp" +#include "FontAtlasGenerator.hpp" +#include "Scene/Texture.hpp" +#include +#include #include #include #include #include -#include "Scene/AtlasMetadata.hpp" -#include "FontAtlasGenerator.hpp" -#include "Scene/Texture.hpp" -#include "msdfgen.h" -#include "msdfgen-ext.h" -#include "msdf-atlas-gen/msdf-atlas-gen.h" -#define MSDFGEN_AVAILABLE +#define MSDFGEN_AVAILABLE 1 namespace OpenVulkano::Scene { - using namespace msdfgen; - using namespace msdf_atlas; - using namespace OpenVulkano::Scene; - class MsdfFontAtlasGenerator : public FontAtlasGenerator { public: - using SdfGenerator = ImmediateAtlasGenerator>; - static Charset LoadAllGlyphs(const std::variant>& data); + using SdfGenerator = msdf_atlas::ImmediateAtlasGenerator>; + static msdf_atlas::Charset LoadAllGlyphs(const std::variant>& data); void GenerateAtlas(const std::string& fontFile, const std::set& charset, const std::optional& pngOutput = std::nullopt) override; void GenerateAtlas(const Array& fontData, int length, const std::set& charset, const std::optional& pngOutput = std::nullopt) override; - void GenerateAtlas(const std::string& fontFile, const Charset& charset = Charset::ASCII, + void GenerateAtlas(const std::string& fontFile, const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII, const std::optional& pngOutput = std::nullopt); - void GenerateAtlas(const msdfgen::byte* fontData, int length, const Charset& charset = Charset::ASCII, + void GenerateAtlas(const msdfgen::byte* fontData, int length, + const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII, const std::optional& pngOutput = std::nullopt); void SaveAtlasMetadataInfo(const std::string& outputFile, bool packIntoSingleFile = true) const override; const Texture& GetAtlas() const override { return m_atlasTex; } std::map& GetGlyphsInfo() override { return m_symbols; } AtlasMetadata& GetAtlasMetadata() override { return m_meta; } SdfGenerator& GetFontAtlasGenerator() { return m_generator; } + private: - void InitFreetypeFromFile(FreetypeHandle*& ft, FontHandle*& font, const std::string& file); - void InitFreetypeFromBuffer(FreetypeHandle*& ft, FontHandle*& font, const msdfgen::byte* fontData, int length); - void Generate(FreetypeHandle* ft, FontHandle* font, const Charset& chset, + void InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, const std::string& file); + void InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, + const msdfgen::byte* fontData, int length); + void Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset, const std::optional& pngOutput); - void SavePng(const BitmapConstRef& storage, const std::string& output, int channels) const; + void SavePng(const msdfgen::BitmapConstRef& storage, const std::string& output, + int channels) const; + private: SdfGenerator m_generator; Texture m_atlasTex; diff --git a/openVulkanoCpp/Scene/TextDrawable.cpp b/openVulkanoCpp/Scene/TextDrawable.cpp index c235a4c..386bbf2 100644 --- a/openVulkanoCpp/Scene/TextDrawable.cpp +++ b/openVulkanoCpp/Scene/TextDrawable.cpp @@ -12,9 +12,11 @@ #include "Scene/FontAtlasGenerator.hpp" #include "Base/Logger.hpp" #include "Host/ResourceLoader.hpp" +#include "Image/ImageLoader.hpp" +#include "DataFormat.hpp" +#include "Base/Logger.hpp" #include #include -#include "Image/ImageLoader.hpp" namespace OpenVulkano::Scene { @@ -210,4 +212,14 @@ namespace OpenVulkano::Scene } SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer); } + + void TextDrawable::SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator) + { + if (!fontAtlasGenerator || fontAtlasGenerator->GetGlyphsInfo().empty()) + { + Logger::RENDER->error("FontAtlasGenerator is either nullptr or doesn't contain glyphs info"); + return; + } + m_fontAtlasGenerator = fontAtlasGenerator; + } } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/TextDrawable.hpp b/openVulkanoCpp/Scene/TextDrawable.hpp index 3575768..8f26bea 100644 --- a/openVulkanoCpp/Scene/TextDrawable.hpp +++ b/openVulkanoCpp/Scene/TextDrawable.hpp @@ -6,24 +6,20 @@ #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 "Material.hpp" #include "Geometry.hpp" #include "UniformBuffer.hpp" -#include "Base/Logger.hpp" #include "AtlasMetadata.hpp" #include "Image/Image.hpp" #include -#include "FontAtlasGenerator.hpp" namespace OpenVulkano::Scene { + + class FontAtlasGenerator; + struct TextConfig { Math::Vector4f textColor = { 1, 1, 1, 1 }; @@ -51,15 +47,7 @@ namespace OpenVulkano::Scene void SetShader(Shader* shader) { m_shader = shader; } TextConfig& GetConfig() { return m_cfg; } Shader* GetShader() { return m_shader; } - void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator) - { - if (!fontAtlasGenerator || fontAtlasGenerator->GetGlyphsInfo().empty()) - { - Logger::RENDER->error("FontAtlasGenerator is either nullptr or doesn't contain glyphs info"); - return; - } - m_fontAtlasGenerator = fontAtlasGenerator; - } + void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator); FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; } private: Geometry m_geometry;