Skip to content

Commit

Permalink
Added msdf-atlas-gen submodule + basic example in Font.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCherno committed Jan 23, 2023
1 parent e4b0493 commit e404b00
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
[submodule "Hazel/vendor/Box2D"]
path = Hazel/vendor/Box2D
url = https://github.com/thecherno/box2d
[submodule "Hazel\\vendor\\msdf-atlas-gen"]
path = Hazel\\vendor\\msdf-atlas-gen
url = https://github.com/TheCherno/msdf-atlas-gen
2 changes: 2 additions & 0 deletions Dependencies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ IncludeDir["mono"] = "%{wks.location}/Hazel/vendor/mono/include"
IncludeDir["shaderc"] = "%{wks.location}/Hazel/vendor/shaderc/include"
IncludeDir["SPIRV_Cross"] = "%{wks.location}/Hazel/vendor/SPIRV-Cross"
IncludeDir["VulkanSDK"] = "%{VULKAN_SDK}/Include"
IncludeDir["msdfgen"] = "%{wks.location}/Hazel/vendor/msdf-atlas-gen/msdfgen"
IncludeDir["msdf_atlas_gen"] = "%{wks.location}/Hazel/vendor/msdf-atlas-gen/msdf-atlas-gen"

LibraryDir = {}

Expand Down
3 changes: 3 additions & 0 deletions Hazel/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ project "Hazel"
"%{IncludeDir.Glad}",
"%{IncludeDir.ImGui}",
"%{IncludeDir.glm}",
"%{IncludeDir.msdfgen}",
"%{IncludeDir.msdf_atlas_gen}",
"%{IncludeDir.stb_image}",
"%{IncludeDir.entt}",
"%{IncludeDir.mono}",
Expand All @@ -53,6 +55,7 @@ project "Hazel"
"GLFW",
"Glad",
"ImGui",
"msdf-atlas-gen",
"yaml-cpp",
"opengl32.lib",

Expand Down
36 changes: 36 additions & 0 deletions Hazel/src/Hazel/Renderer/Font.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "hzpch.h"
#include "Font.h"

#undef INFINITE
#include "msdf-atlas-gen.h"

namespace Hazel {

Font::Font(const std::filesystem::path& filepath)
{
msdfgen::FreetypeHandle* ft = msdfgen::initializeFreetype();
if (ft)
{
std::string fileString = filepath.string();
msdfgen::FontHandle* font = msdfgen::loadFont(ft, fileString.c_str());
if (font)
{
msdfgen::Shape shape;
if (msdfgen::loadGlyph(shape, font, 'C'))
{
shape.normalize();
// max. angle
msdfgen::edgeColoringSimple(shape, 3.0);
// image width, height
msdfgen::Bitmap<float, 3> msdf(32, 32);
// range, scale, translation
msdfgen::generateMSDF(msdf, shape, 4.0, 1.0, msdfgen::Vector2(4.0, 4.0));
msdfgen::savePng(msdf, "output.png");
}
msdfgen::destroyFont(font);
}
msdfgen::deinitializeFreetype(ft);
}
}

}
13 changes: 13 additions & 0 deletions Hazel/src/Hazel/Renderer/Font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

namespace Hazel {

class Font
{
public:
Font(const std::filesystem::path& font);


};

}
1 change: 1 addition & 0 deletions Hazel/vendor/msdf-atlas-gen
Submodule msdf-atlas-gen added at b50e10
4 changes: 4 additions & 0 deletions Hazelnut/src/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Hazel/Utils/PlatformUtils.h"
#include "Hazel/Math/Math.h"
#include "Hazel/Scripting/ScriptEngine.h"
#include "Hazel/Renderer/Font.h"

#include <imgui/imgui.h>

Expand All @@ -16,6 +17,9 @@ namespace Hazel {
EditorLayer::EditorLayer()
: Layer("EditorLayer"), m_CameraController(1280.0f / 720.0f), m_SquareColor({ 0.2f, 0.3f, 0.8f, 1.0f })
{

Font font("assets/fonts/opensans/OpenSans-Regular.ttf");

}

void EditorLayer::OnAttach()
Expand Down
1 change: 1 addition & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ group "Dependencies"
include "Hazel/vendor/Box2D"
include "Hazel/vendor/GLFW"
include "Hazel/vendor/Glad"
include "Hazel/vendor/msdf-atlas-gen"
include "Hazel/vendor/imgui"
include "Hazel/vendor/yaml-cpp"
group ""
Expand Down

0 comments on commit e404b00

Please sign in to comment.