Fix memleak
This commit is contained in:
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLuint texture;
|
|
||||||
|
|
||||||
namespace JGL
|
namespace JGL
|
||||||
{
|
{
|
||||||
@@ -152,17 +151,17 @@ namespace JGL
|
|||||||
|
|
||||||
FT_Set_Pixel_Sizes(face, 0, size);
|
FT_Set_Pixel_Sizes(face, 0, size);
|
||||||
|
|
||||||
const char* c;
|
GLuint textures[text.size()];
|
||||||
for (c = text.c_str(); *c; c++)
|
for (int i = 0; i < text.length(); i++)
|
||||||
{
|
{
|
||||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
if (FT_Load_Char(face, text.c_str()[i], FT_LOAD_RENDER))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
FT_GlyphSlot g = face->glyph;
|
FT_GlyphSlot g = face->glyph;
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &textures[i]);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, textures[i]);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@@ -200,8 +199,9 @@ namespace JGL
|
|||||||
|
|
||||||
x += (g->advance.x >> 6) * scale;
|
x += (g->advance.x >> 6) * scale;
|
||||||
y += (g->advance.y >> 6) * scale;
|
y += (g->advance.y >> 6) * scale;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
for (auto& t : textures)
|
||||||
|
glDeleteTextures(1, &t);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,6 @@ namespace JGL
|
|||||||
{
|
{
|
||||||
void DrawLine3D(const Color3& color, const Vector3& A, const Vector3& B, float thickness)
|
void DrawLine3D(const Color3& color, const Vector3& A, const Vector3& B, float thickness)
|
||||||
{
|
{
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glLineWidth(thickness);
|
glLineWidth(thickness);
|
||||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||||
@@ -226,23 +225,24 @@ namespace JGL
|
|||||||
float y = pos.y;
|
float y = pos.y;
|
||||||
float z = pos.z;
|
float z = pos.z;
|
||||||
GLfloat currentColor[4];
|
GLfloat currentColor[4];
|
||||||
|
GLuint textures[text.size()];
|
||||||
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
||||||
glUseProgram(0); // Fixed-function pipeline.
|
glUseProgram(0); // Fixed-function pipeline.
|
||||||
glColor4f(color.r, color.g, color.b, 1.0f);
|
glColor4f(color.r, color.g, color.b, 1.0f);
|
||||||
|
|
||||||
FT_Set_Pixel_Sizes(face, 0, size);
|
FT_Set_Pixel_Sizes(face, 0, size);
|
||||||
|
|
||||||
const char* c;
|
//for (c = text.c_str(); *c; c++)
|
||||||
for (c = text.c_str(); *c; c++)
|
for (int i = 0; i < text.length(); i++)
|
||||||
{
|
{
|
||||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
if (FT_Load_Char(face, text.c_str()[i], FT_LOAD_RENDER))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
FT_GlyphSlot g = face->glyph;
|
FT_GlyphSlot g = face->glyph;
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &textures[i]);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, textures[i]);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@@ -283,6 +283,10 @@ namespace JGL
|
|||||||
y += (g->advance.y >> 6) * scale;
|
y += (g->advance.y >> 6) * scale;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& t : textures)
|
||||||
|
glDeleteTextures(1, &t);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
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.
|
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user