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:
@@ -6,6 +6,9 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
// LMFAO
|
||||
extern "C" typedef struct FT_FaceRec_* FT_Face;
|
||||
extern "C" typedef struct FT_LibraryRec_* FT_Library;
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
@@ -18,13 +21,14 @@ namespace JGL
|
||||
public:
|
||||
/// Default constructor does not initialize any members
|
||||
Font() = default;
|
||||
Font(std::filesystem::path path);
|
||||
Font(const std::filesystem::path& path);
|
||||
/// Destructor handles freeing of the underlying asset handle.
|
||||
~Font();
|
||||
static Font LoadTTF(std::filesystem::path filepath);
|
||||
static Font LoadTTF(const std::filesystem::path& filepath);
|
||||
static std::vector<Font> GetLoadedFonts();
|
||||
Vector2 MeasureString(const std::string& text, float ptSize);
|
||||
public:
|
||||
int index = 0;
|
||||
FT_Face face;
|
||||
};
|
||||
}
|
@@ -53,7 +53,7 @@ namespace JGL {
|
||||
};
|
||||
|
||||
bool Update(const Vector2& window_size);
|
||||
bool InitTextEngine();
|
||||
//bool InitTextEngine();
|
||||
Font LoadFont(const std::string& font_path); // TODO: Fully deprecate
|
||||
void PurgeFontCache();
|
||||
|
||||
|
16
main.cpp
16
main.cpp
@@ -58,8 +58,8 @@ struct point {
|
||||
GLfloat t;
|
||||
};
|
||||
|
||||
JGL::Font FreeSans;
|
||||
JGL::Font Jupiteroid;
|
||||
JGL::Font* FreeSans;
|
||||
JGL::Font* Jupiteroid;
|
||||
|
||||
class JGLDemoWindow : public ReWindow::RWindow
|
||||
{
|
||||
@@ -71,8 +71,8 @@ public:
|
||||
|
||||
gladLoadGL();
|
||||
JGL::Update(getSize());
|
||||
FreeSans = JGL::Font("assets/fonts/FreeSans.ttf");
|
||||
Jupiteroid = JGL::Font("assets/fonts/Jupiteroid.ttf");
|
||||
FreeSans = new JGL::Font("assets/fonts/FreeSans.ttf");
|
||||
Jupiteroid = new JGL::Font("assets/fonts/Jupiteroid.ttf");
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
J3D::Begin();
|
||||
J3D::DrawLine(JGL::Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
|
||||
J3D::DrawLine(JGL::Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
|
||||
J3D::DrawString(JGL::Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f},textAngle, 1.f, 32, FreeSans);
|
||||
J3D::DrawString(JGL::Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f},textAngle, 1.f, 32, *FreeSans);
|
||||
J3D::End();
|
||||
|
||||
|
||||
@@ -119,9 +119,9 @@ public:
|
||||
J2D::OutlineTriangle(Colors::Blue, {{100, 275}, {0, 275}, {100, 375}});
|
||||
J2D::DrawGradientLine(JGL::Colors::Red, JGL::Colors::Blue, {105, 375}, {200, 275}, 2);
|
||||
|
||||
J2D::DrawString(JGL::Colors::Green, "Jupteroid Font", 0.f, 16, 1.f, 16, Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, 33, 1,16, Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, 50, 1,16, Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::Green, "Jupteroid Font", 0.f, 16, 1.f, 16, *Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, 33, 1,16, *Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, 50, 1,16, *Jupiteroid);
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
|
@@ -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