Half-ass Font class implementation
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m30s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m30s
This commit is contained in:
@@ -19,6 +19,9 @@ bool wasBlendEnabled = false;
|
||||
bool wasColorArrayEnabled = false;
|
||||
GLint activeTextureUnit = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
namespace JGL {
|
||||
using namespace J3ML;
|
||||
Vector2 wS;
|
||||
@@ -28,6 +31,7 @@ namespace JGL {
|
||||
return JGL::InitTextEngine();
|
||||
}
|
||||
|
||||
|
||||
void J2D::Begin() {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <JGL/Font.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -7,22 +7,18 @@
|
||||
#if __linux__
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_OUTLINE_H
|
||||
#endif
|
||||
#if _WIN32
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#endif
|
||||
|
||||
#include <JGL/Font.h>
|
||||
|
||||
namespace JGL::Detail
|
||||
{
|
||||
|
||||
/// ANOTHER Wrapper class to hide FT_Face and it's associated bullshit from user-facing API.
|
||||
class FontInternals
|
||||
{
|
||||
public:
|
||||
FT_Face face;
|
||||
};
|
||||
|
||||
FT_Library ft;
|
||||
|
||||
std::vector<Font> fonts;
|
||||
@@ -33,8 +29,8 @@ namespace JGL::Detail
|
||||
return -1;
|
||||
|
||||
Font font;
|
||||
FT_Face face;
|
||||
if (FT_New_Face(ft, font_path.c_str(), 0, &face)) {
|
||||
|
||||
if (FT_New_Face(ft, font_path.c_str(), 0, &font.face)) {
|
||||
std::cout << "Error::FREETYPE: Failed to load font!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
@@ -47,7 +43,7 @@ namespace JGL::Detail
|
||||
font.index = newIndex;
|
||||
|
||||
fonts.push_back(font);
|
||||
faces.push_back(face);
|
||||
|
||||
std::cout << "Loaded font from " << font_path << " with index " << newIndex << std::endl;
|
||||
return newIndex;
|
||||
}
|
||||
@@ -64,7 +60,7 @@ namespace JGL::Detail
|
||||
while (iter != fonts.end())
|
||||
{
|
||||
if (iter->index == font_index){
|
||||
FT_Done_Face(faces[iter->index]);
|
||||
FT_Done_Face(iter->face);
|
||||
iter = fonts.erase(iter);
|
||||
} else ++iter;
|
||||
}
|
||||
@@ -74,13 +70,17 @@ namespace JGL::Detail
|
||||
namespace JGL
|
||||
{
|
||||
|
||||
Font::Font(std::filesystem::path path)
|
||||
bool InitTextEngine()
|
||||
{
|
||||
return Detail::InitTextEngine();
|
||||
}
|
||||
|
||||
Font::Font(const std::filesystem::path& path)
|
||||
{
|
||||
if (Detail::ft == nullptr)
|
||||
throw new std::runtime_error("Error::FREETYPE: FT_Library was not initialized before attempting to load a font!");
|
||||
|
||||
Font font;
|
||||
FT_Face face;
|
||||
if (FT_New_Face(Detail::ft, path.c_str(), 0, &face)) {
|
||||
std::cout << "Error::FREETYPE: Failed to load font!" << std::endl;
|
||||
throw new std::runtime_error("Error::FREETYPE: Failed to load font!");
|
||||
@@ -99,7 +99,7 @@ namespace JGL
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
Detail::UnloadFont(this->index);
|
||||
//Detail::UnloadFont(this->index);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace JGL
|
||||
}
|
||||
|
||||
|
||||
Font Font::LoadTTF(std::filesystem::path path)
|
||||
Font Font::LoadTTF(const std::filesystem::path& path)
|
||||
{
|
||||
return Font(path);
|
||||
}
|
||||
|
@@ -1,5 +1,16 @@
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
|
||||
#if __linux__
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_OUTLINE_H
|
||||
#endif
|
||||
#if _WIN32
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#endif
|
||||
|
||||
#include <JGL/Font.h>
|
||||
#include <JGL/FontCache.h>
|
||||
|
||||
@@ -21,7 +32,7 @@ namespace JGL {
|
||||
// if (f.index == font.index)
|
||||
// font = f;
|
||||
|
||||
auto face = GetFTFace();
|
||||
|
||||
|
||||
if (font.face == nullptr)
|
||||
return;
|
||||
@@ -158,8 +169,8 @@ namespace JGL {
|
||||
|
||||
//Font font;
|
||||
//for (auto& f : Font::GetLoadedFonts())
|
||||
// if (f.index == font.index)
|
||||
// font = f;
|
||||
//if (f.index == font.index)
|
||||
//font = f;
|
||||
if (font.face == NULL) {
|
||||
std::cout << "null font" << std::endl;
|
||||
return;
|
||||
|
Reference in New Issue
Block a user