diff --git a/SHADE_Engine/src/Assets/Asset Types/SHFontAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHFontAsset.h new file mode 100644 index 00000000..89379ac3 --- /dev/null +++ b/SHADE_Engine/src/Assets/Asset Types/SHFontAsset.h @@ -0,0 +1,44 @@ +/*************************************************************************//** + * \file SHFontAsset.h + * \author Brandon Mak + * \date 5 November 2022 + * \brief + * + * Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. + *****************************************************************************/ +#pragma once + +#include "SHAssetData.h" +#include "SH_API.h" +#include +#include +#include "msdf-atlas-gen/msdf-atlas-gen.h" + +namespace SHADE +{ + struct SH_API SHFontAsset : SHAssetData + { + /*-----------------------------------------------------------------------*/ + /* MEMBER VARIABLES */ + /*-----------------------------------------------------------------------*/ + //! Individual glyph data + std::vector glyphData; + + //! MSDF's data structure containing the raw data of the atlas + msdfgen::Bitmap fontBitmap; + + //! Used for getting data of the font + msdf_atlas::FontGeometry fontGeometry; + + //! Handle to the font loaded. We will use this when we initialize font data. + //! This is mainly the asset part of fonts. + msdfgen::FontHandle* fontHandle; + + //! Name of the shader file (without parent path) + std::string fontName; + + + }; +} diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp new file mode 100644 index 00000000..da2f966a --- /dev/null +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.cpp @@ -0,0 +1,53 @@ +#include "SHpch.h" +#include "SHFontLoader.h" +#include "Assets/Asset Types/SHFontAsset.h" +#include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h" + +namespace SHADE +{ + SHADE::SHAssetData* SHFontLoader::Load(AssetPath path) + { + //auto result = new SHFontAsset(); + + //// save the font name + //result->fontName = path.stem().stem().string(); + + //result->fontHandle = msdfgen::loadFont(SHFreetypeInstance::GetFreetypeHandle(), path.string().c_str()); + + ////result->fontGeometry = msdf_atlas::FontGeometry(&result->glyphData); + + //result->fontGeometry.loadCharset(font, 1.0f, msdf_atlas::Charset::ASCII); + + //// Apply MSDF edge coloring + //const double maxCornerAngle = 3.0; + //for (GlyphGeometry& glyph : glyphData) + // glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, maxCornerAngle, 0); + + //TightAtlasPacker atlasPacker; + //atlasPacker.setDimensionsConstraint(TightAtlasPacker::DimensionsConstraint::SQUARE); + + //atlasPacker.setMinimumScale(64.0); + //atlasPacker.setPixelRange(2.0); + //atlasPacker.setMiterLimit(1.0); + //atlasPacker.pack(glyphData.data(), static_cast(glyphData.size())); + + + //int width = 0, height = 0; + //atlasPacker.getDimensions(width, height); + + //ImmediateAtlasGenerator> generator(width, height); + //GeneratorAttributes genAttribs; + //generator.setAttributes(genAttribs); + //generator.setThreadCount(4); + //generator.generate(glyphData.data(), static_cast(glyphData.size())); + + + return nullptr; + } + + void SHFontLoader::Write(SHAssetData const* data, AssetPath path) + { + + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.h b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.h new file mode 100644 index 00000000..7221d2f2 --- /dev/null +++ b/SHADE_Engine/src/Assets/Libraries/Loaders/SHFontLoader.h @@ -0,0 +1,24 @@ +/*************************************************************************//** + * \file SHSFontLoader.h + * \author Loh Xiao Qi + * \date 23 10 2022 + * \brief + * + * Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. + *****************************************************************************/ + +#pragma once + +#include "Assets/Libraries/Loaders/SHAssetLoader.h" + +namespace SHADE +{ + struct SHFontLoader : SHAssetLoader + { + + SHAssetData* Load(AssetPath path) override; + void Write(SHAssetData const* data, AssetPath path) override; + }; +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 573c7f7f..c7b864d5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -42,6 +42,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/SHVkUtil.h" #include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h" #include "../Meshes/SHPrimitiveGenerator.h" +#include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h" namespace SHADE { @@ -380,6 +381,7 @@ namespace SHADE void SHGraphicsSystem::Exit(void) { + SHFreetypeInstance::Exit(); } #pragma endregion INIT_EXIT diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontAtlasData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontAtlasData.cpp new file mode 100644 index 00000000..6ea1bceb --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontAtlasData.cpp @@ -0,0 +1,7 @@ +#include "SHpch.h" +#include "SHFontAtlasData.h" + +namespace SHADE +{ + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontAtlasData.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontAtlasData.h new file mode 100644 index 00000000..1e6e7470 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFontAtlasData.h @@ -0,0 +1,7 @@ +#pragma once + + +namespace SHADE +{ + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.cpp new file mode 100644 index 00000000..9e629020 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.cpp @@ -0,0 +1,27 @@ +#include "SHpch.h" +#include "SHFreetypeInstance.h" +#include "msdf-atlas-gen/msdf-atlas-gen.h" +#include "msdfgen-ext.h" + +namespace SHADE +{ + + msdfgen::FreetypeHandle* SHFreetypeInstance::freetypeHandle = nullptr; + + void SHFreetypeInstance::Init(void) noexcept + { + // initialize freetype + freetypeHandle = msdfgen::initializeFreetype(); + } + + void SHFreetypeInstance::Exit(void) noexcept + { + msdfgen::deinitializeFreetype(freetypeHandle); + } + + msdfgen::FreetypeHandle* SHFreetypeInstance::GetFreetypeHandle(void) noexcept + { + return freetypeHandle; + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h new file mode 100644 index 00000000..4d1bed9c --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h @@ -0,0 +1,23 @@ +#pragma once + +namespace msdfgen +{ + class FreetypeHandle; +} + +namespace SHADE +{ + class SHFreetypeInstance + { + private: + //! Only need this to be initialized once + static msdfgen::FreetypeHandle* freetypeHandle; + + public: + static void Init (void) noexcept; + static void Exit (void) noexcept; + + static msdfgen::FreetypeHandle* GetFreetypeHandle(void) noexcept; + + }; +}