Move glPixelStore call inside of InitTextEngine so users don't need to call it. Also adjusted Color3 and Color4, more work coming soon.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 2m18s

This commit is contained in:
2024-07-18 13:45:11 -04:00
parent 4ff8d8ff07
commit 26d17dae38
6 changed files with 73 additions and 19 deletions

View File

@@ -5,19 +5,23 @@
namespace JGL
{
using namespace J3ML;
struct Color3 {
class Color3 {
public:
u8 r;
u8 g;
u8 b;
Color3 Lerp(const Color3& rhs, float alpha) const;
Color3(u8 R, u8 G, u8 B) : r(R), g(G), b(B) {}
u8 RedChannel () const { return r; }
u8 GreenChannel() const { return g; }
u8 BlueChannel () const { return b; }
float RedChannelNormalized () const { return static_cast<float>(r) / 255.f;}
float BlueChannelNormalized() const { return static_cast<float>(b) / 255.f;}
float GreenChannelNormalized() const { return static_cast<float>(g) / 255.f;}
public:
Color3(u8 R, u8 G, u8 B);
static Color3 FromHex(const std::string& hexCode);
public:
Color3 Lerp(const Color3& rhs, float alpha) const;
u8 RedChannel () const;
u8 GreenChannel() const;
u8 BlueChannel () const;
float RedChannelNormalized () const;
float BlueChannelNormalized() const;
float GreenChannelNormalized() const;
};

View File

@@ -6,12 +6,25 @@ namespace JGL
{
class Color4 {
public:
explicit Color4(const Color3& color3, unsigned int alpha) {r = color3.r; g = color3.g; b = color3.b; a = alpha;}
Color4(int red, int green, int blue, int alpha = 127) : r(red), g(green), b(blue), a(alpha) {}
static Color4 FromColor3(const Color3& color3, unsigned int alpha = 127) {return Color4(color3, alpha);}
int r;
int g;
int b;
int a;
u8 r;
u8 g;
u8 b;
u8 a;
public:
explicit Color4(const Color3& color3, u8 alpha = 255);
Color4(u8 red, u8 green, u8 blue, u8 alpha = 255);
static Color4 FromColor3(const Color3& color3, u8 alpha = 255);
static Color4 FromHex(const std::string& hexCode, u8 alpha = 255);
public:
u8 RedChannel() const;
u8 GreenChannel() const;
u8 BlueChannel() const;
u8 AlphaChannel() const;
float RedChannelNormalized() const;
float GreenChannelNormalized() const;
float BlueChannelNormalized() const;
float AlphaChannelNormalized() const;
};
}

View File

@@ -1,4 +1,4 @@
#include <glad/glad.h>
#include <JGL/JGL.h>
#include <rewindow/types/window.h>
#include <JGL/Colors.h>
@@ -76,7 +76,6 @@ public:
FreeSans = JGL::Font("assets/fonts/FreeSans.ttf");
Jupiteroid = JGL::Font("assets/fonts/Jupiteroid.ttf");
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf(perspective(75, aspect, 0.001, 100).data());

View File

@@ -3,4 +3,17 @@
namespace JGL
{
u8 Color3::RedChannel() const { return r; }
u8 Color3::GreenChannel() const { return g; }
u8 Color3::BlueChannel() const { return b; }
float Color3::RedChannelNormalized() const { return static_cast<float>(r) / 255.f;}
float Color3::BlueChannelNormalized() const { return static_cast<float>(b) / 255.f;}
float Color3::GreenChannelNormalized() const { return static_cast<float>(g) / 255.f;}
Color3::Color3(u8 R, u8 G, u8 B) : r(R), g(G), b(B) {}
}

View File

@@ -3,4 +3,25 @@
namespace JGL
{
Color4::Color4(u8 red, u8 green, u8 blue, u8 alpha) : r(red), g(green), b(blue), a(alpha) {}
Color4::Color4(const Color3 &color3, u8 alpha) {r = color3.r; g = color3.g; b = color3.b; a = alpha;}
Color4 Color4::FromColor3(const Color3 &color3, u8 alpha) {return Color4(color3, alpha);}
u8 Color4::RedChannel() const { return r;}
u8 Color4::GreenChannel() const { return g;}
u8 Color4::BlueChannel() const {return b;}
u8 Color4::AlphaChannel() const {return a;}
float Color4::RedChannelNormalized() const {return static_cast<float>(r/255.f); }
float Color4::GreenChannelNormalized() const {return static_cast<float>(g/255.f); }
float Color4::BlueChannelNormalized() const {return static_cast<float>(b/255.f); }
float Color4::AlphaChannelNormalized() const {return static_cast<float>(a/255.f); }
}

View File

@@ -2,7 +2,7 @@
#include <vector>
#include <string>
#include <iostream>
#include <glad/glad.h>
#if __linux__
#include <freetype2/ft2build.h>
@@ -49,6 +49,10 @@ namespace JGL::Detail
}
bool InitTextEngine() {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // NOTE: This MUST be called for text rendering to work properly!!!
// Keep note of this, might cause problems later?
if (ft != nullptr)
throw std::runtime_error("Error::FREETYPE: FT_Library was initialized but is already initialized.");