Delete our glyph textures on destruction.

This commit is contained in:
Andrzej Kapolka 2013-04-30 10:04:01 -07:00
parent a24f215f09
commit 34f2a28114
2 changed files with 10 additions and 0 deletions

View file

@ -24,6 +24,10 @@ TextRenderer::TextRenderer(const char* family, int pointSize, int weight, bool i
_metrics(_font), _x(IMAGE_SIZE), _y(IMAGE_SIZE), _rowHeight(0) {
}
TextRenderer::~TextRenderer() {
glDeleteTextures(_textureIDs.size(), _textureIDs.constData());
}
void TextRenderer::draw(int x, int y, const char* str) {
glEnable(GL_TEXTURE_2D);
@ -105,6 +109,7 @@ const Glyph& TextRenderer::getGlyph(char c) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_SIZE, IMAGE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
_textureIDs.append(_textureID);
} else {
glBindTexture(GL_TEXTURE_2D, _textureID);

View file

@ -13,6 +13,7 @@
#include <QFontMetrics>
#include <QHash>
#include <QImage>
#include <QVector>
class Glyph;
@ -20,6 +21,7 @@ class TextRenderer {
public:
TextRenderer(const char* family, int pointSize = -1, int weight = -1, bool italic = false);
~TextRenderer();
const QFontMetrics& metrics() const { return _metrics; }
@ -49,6 +51,9 @@ private:
// the height of the current row of characters
int _rowHeight;
// the list of all texture ids for which we're responsible
QVector<GLuint> _textureIDs;
};
class Glyph {