Compare commits

...

4 Commits

Author SHA1 Message Date
cf72d92c28 Merge branch 'master' of https://git.redacted.cc/josh/JGL 2024-05-29 22:18:41 -04:00
5d99f8ec1f update 2024-05-29 22:18:40 -04:00
a388ee8021 Implement proper GL state management in DrawString2D, DrawString3D 2024-05-29 15:27:24 -04:00
41916a4089 Update JGL.cpp 2024-05-29 15:05:06 -04:00
2 changed files with 18 additions and 5 deletions

View File

@@ -31,7 +31,7 @@ CPMAddPackage(
CPMAddPackage(
NAME GLAD
URL https://git.redacted.cc/Redacted/glad/archive/v2.1.zip
URL https://git.redacted.cc/Redacted/glad/archive/v2.1ext_mt.zip
)
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}")
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")

View File

@@ -2,6 +2,7 @@
// Created by dawsh on 1/17/24.
//
#include <vector>
#include <glad/glad.h>
#include <JGL/JGL.h>
#include <freetype2/ft2build.h>
@@ -9,7 +10,6 @@
#include <JGL/Color3.h>
#include <iostream>
GLuint program;
namespace JGL
@@ -147,6 +147,10 @@ namespace JGL
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size) {
glUseProgram(0); // Fixed-function pipeline.
GLfloat currentColor[4];
glGetFloatv(GL_CURRENT_COLOR, currentColor);
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
FT_Set_Pixel_Sizes(face, 0, size);
@@ -158,8 +162,10 @@ namespace JGL
continue;
FT_GlyphSlot g = face->glyph;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textures[i]);
glBindTexture(GL_TEXTURE_2D, textures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -202,7 +208,11 @@ namespace JGL
}
for (auto& t : textures)
glDeleteTextures(1, &t);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
}
}
@@ -239,8 +249,10 @@ namespace JGL
continue;
FT_GlyphSlot g = face->glyph;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textures[i]);
glBindTexture(GL_TEXTURE_2D, textures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -286,7 +298,8 @@ namespace JGL
for (auto& t : textures)
glDeleteTextures(1, &t);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
}