From a388ee80219f75141d2b2fa8fba78f8ee46ed5cf Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 29 May 2024 15:27:24 -0400 Subject: [PATCH] Implement proper GL state management in DrawString2D, DrawString3D --- src/JGL/JGL.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/JGL/JGL.cpp b/src/JGL/JGL.cpp index 35cfe42..e1c2d4d 100644 --- a/src/JGL/JGL.cpp +++ b/src/JGL/JGL.cpp @@ -9,7 +9,6 @@ #include #include - GLuint program; namespace JGL @@ -147,6 +146,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 +161,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 +207,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. } }