Include Jupiteroid as a default font
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m41s

This commit is contained in:
2024-12-04 16:14:38 -05:00
parent 122644a013
commit 38bb1b22ce
9 changed files with 8721 additions and 26 deletions

Binary file not shown.

View File

@@ -28,13 +28,29 @@
#include <J3ML/Geometry/Triangle2D.hpp>
#include <J3ML/J3ML.hpp>
#include <JGL/types/Font.h>
#include <JGL/types/VRamList.h>
// Fonts that are included by default.
namespace JGL::Fonts {
void Init();
// Built in fonts.
inline Font Jupiteroid;
}
// Simple shapes that are pre-computed and used in some draw functions.
namespace JGL::ShapeCache {
inline VRamList* cube_vertex_data = nullptr;
inline VRamList* cube_index_data = nullptr;
void Init();
}
/// OpenGL Wrapper for rendering 2D & 3D graphics in both a 2D and 3D context.
namespace JGL {
using namespace J3ML::LinearAlgebra;
using namespace J3ML::Geometry;
[[nodiscard]] bool Init(const Vector2& window_size, float fovY, float far_plane);
/// @param window_size
@@ -336,7 +352,7 @@ namespace JGL::J2D {
/// @param scale The value (in both axes) to scale the text by. Defaults to {1,1}.
/// @param size The point-size at which to render the font out. Re-using the same point-size allows efficient glyph caching.
/// @param font The font to use for rendering. @see Font.
void DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font);
void DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font = Fonts::Jupiteroid);
/// Draws an Arc (section of a circle) to the screen.
@@ -652,7 +668,7 @@ namespace JGL::J3D {
/// @param font The font object to use when drawing.
/// @param angle The orientation in 3D space.
/// @param draw_back_face
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngleXYZ& angle = {0, 0, 0}, bool draw_back_face = false);
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font = Fonts::Jupiteroid, const EulerAngleXYZ& angle = {0, 0, 0}, bool draw_back_face = false);
/// Draws a string of text in 3D space that is always facing the exact direction of the camera projection.
void DrawBillboardString();

View File

@@ -1,9 +0,0 @@
#pragma once
#include <JGL/types/VRamList.h>
#include <array>
namespace JGL::ShapeCache {
inline VRamList* cube_vertex_data = nullptr;
inline VRamList* cube_index_data = nullptr;
void Init();
}

View File

@@ -13,8 +13,6 @@ extern "C" typedef struct FT_LibraryRec_* FT_Library;
namespace JGL
{
//bool Init();
bool InitTextEngine();
/// A Font class implementation.
@@ -23,7 +21,8 @@ namespace JGL
public:
/// Default constructor does not initialize any members
Font() = default;
Font(const std::filesystem::path& path);
explicit Font(const std::filesystem::path& path);
Font(const unsigned char* data, const size_t& size);
/// Destructor handles freeing of the underlying asset handle.
~Font();
static Font LoadTTF(const std::filesystem::path& filepath);
@@ -35,6 +34,6 @@ namespace JGL
Vector2 MeasureString(const std::string& text, unsigned int ptSize);
public:
int index = 0;
FT_Face face;
FT_Face face = nullptr;
};
}

View File

@@ -7,10 +7,10 @@
#include <J3ML/Geometry/AABB.hpp>
using J3ML::LinearAlgebra::Vector2;
using namespace JGL::Fonts;
using namespace JGL;
JGL::Font FreeSans;
JGL::Font Jupiteroid;
float fps = 0.0f;
class Gizmo
@@ -111,7 +111,6 @@ public:
Logger::Fatal("Initialization failed.");
FreeSans = JGL::Font("assets/fonts/FreeSans.ttf");
Jupiteroid = JGL::Font("assets/fonts/Jupiteroid.ttf");
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);

8671
src/Fonts.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,6 @@
#include <J3ML/Geometry/OBB.hpp>
#include <JGL/types/VRamList.h>
#include <JGL/types/Font.h>
#include <JGL/ShapeCache.h>
JGL::RenderTarget* render_target = nullptr;
GLfloat oldColor[4] = {0, 0, 0, 1};
@@ -50,6 +49,7 @@ namespace JGL {
}
InitTextEngine();
Fonts::Init();
ShapeCache::Init();
wS = window_size;
j3d_fov = fovY;

View File

@@ -1,4 +1,4 @@
#include <JGL/ShapeCache.h>
#include <JGL/JGL.h>
void JGL::ShapeCache::Init() {
if (!cube_vertex_data) {

View File

@@ -4,6 +4,7 @@
#include <iostream>
#include <glad/glad.h>
#include <JGL/logger/logger.h>
#include <JGL/JGL.h>
#if __linux__
#include <freetype2/ft2build.h>
@@ -58,6 +59,26 @@ namespace JGL {
return Detail::InitTextEngine();
}
Font::Font(const unsigned char* data, const size_t& size) {
if (Detail::ft == nullptr)
throw std::runtime_error("Error::FREETYPE: FT_Library was not initialized before attempting to load a font!");
Font font;
if (FT_New_Memory_Face(Detail::ft, data, size, 0, &face)) {
std::cout << "Error::FREETYPE: Failed to load font!" << std::endl;
throw std::runtime_error("Error::FREETYPE: Failed to load font!");
//return -1;
}
unsigned int newIndex = 0;
for (const auto& f : Detail::fonts)
if (f.index >= newIndex)
newIndex = f.index + 1;
index = newIndex;
Detail::fonts.push_back(font);
std::cout << "Loaded font from memory at " << (const void*) data << " with index " << newIndex << std::endl;
}
Font::Font(const std::filesystem::path& path) {
if (Detail::ft == nullptr)
throw std::runtime_error("Error::FREETYPE: FT_Library was not initialized before attempting to load a font!");
@@ -120,13 +141,13 @@ namespace JGL {
}
jlog::Warning("Measuring a font size that is not cached, This is *super* slow.");
FT_Set_Pixel_Sizes(this->face, ptSize, ptSize);
FT_Set_Pixel_Sizes(Fonts::Jupiteroid.face, ptSize, ptSize);
for (const char& c : text) {
FT_GlyphSlot slot = face->glyph;
auto glyph_index = FT_Get_Char_Index(this->face, c);
FT_GlyphSlot slot = Fonts::Jupiteroid.face->glyph;
auto glyph_index = FT_Get_Char_Index(Fonts::Jupiteroid.face, c);
auto error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
auto error = FT_Load_Glyph(Fonts::Jupiteroid.face, glyph_index, FT_LOAD_DEFAULT);
if (error)
continue;
@@ -149,6 +170,4 @@ namespace JGL {
return extents;
}
}