Text Rendering WIP
This commit is contained in:
parent
1eb6bc5ef2
commit
88530e9909
|
@ -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 <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "msdf-atlas-gen/msdf-atlas-gen.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
struct SH_API SHFontAsset : SHAssetData
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* MEMBER VARIABLES */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
//! Individual glyph data
|
||||||
|
std::vector<msdf_atlas::GlyphGeometry> glyphData;
|
||||||
|
|
||||||
|
//! MSDF's data structure containing the raw data of the atlas
|
||||||
|
msdfgen::Bitmap<msdfgen::byte, 3> 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;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
|
@ -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<int>(glyphData.size()));
|
||||||
|
|
||||||
|
|
||||||
|
//int width = 0, height = 0;
|
||||||
|
//atlasPacker.getDimensions(width, height);
|
||||||
|
|
||||||
|
//ImmediateAtlasGenerator<float, 3, msdfGenerator, BitmapAtlasStorage<float, 3>> generator(width, height);
|
||||||
|
//GeneratorAttributes genAttribs;
|
||||||
|
//generator.setAttributes(genAttribs);
|
||||||
|
//generator.setThreadCount(4);
|
||||||
|
//generator.generate(glyphData.data(), static_cast<int>(glyphData.size()));
|
||||||
|
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHFontLoader::Write(SHAssetData const* data, AssetPath path)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Graphics/SHVkUtil.h"
|
#include "Graphics/SHVkUtil.h"
|
||||||
#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h"
|
#include "Graphics/RenderGraph/SHRenderGraphNodeCompute.h"
|
||||||
#include "../Meshes/SHPrimitiveGenerator.h"
|
#include "../Meshes/SHPrimitiveGenerator.h"
|
||||||
|
#include "Graphics/MiddleEnd/TextRendering/SHFreetypeInstance.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -380,6 +381,7 @@ namespace SHADE
|
||||||
|
|
||||||
void SHGraphicsSystem::Exit(void)
|
void SHGraphicsSystem::Exit(void)
|
||||||
{
|
{
|
||||||
|
SHFreetypeInstance::Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma endregion INIT_EXIT
|
#pragma endregion INIT_EXIT
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHFontAtlasData.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue