From 34ac035c1befa6046387ada3aa14e556025ffcfa Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Mon, 23 Aug 2010 21:24:16 -0500 Subject: [PATCH] converted Font drawing to use display lists - should increase draw speed --- src/modules/graphics/opengl/Font.cpp | 15 +++++++++--- src/modules/graphics/opengl/Font.h | 1 + src/modules/graphics/opengl/Glyph.cpp | 35 +++++++-------------------- src/modules/graphics/opengl/Glyph.h | 4 +-- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 773f27cde..3b5b9aa60 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -34,10 +34,13 @@ namespace opengl : height(data->getHeight()), lineHeight(1.25), mSpacing(1) { glyphs = new Glyph*[MAX_CHARS]; + for(unsigned int i = 0; i < MAX_CHARS; i++) { glyphs[i] = new Glyph(data->getGlyphData(i)); - glyphs[i]->load(); + glNewList(list + i, GL_COMPILE); + glyphs[i]->load(); + glEndList(); widths[i] = data->getGlyphData(i)->getWidth(); spacing[i] = data->getGlyphData(i)->getAdvance(); bearingX[i] = data->getGlyphData(i)->getBearingX(); @@ -72,7 +75,10 @@ namespace opengl for (unsigned int i = 0; i < text.size(); i++) { int g = (int)text[i]; if (!glyphs[g]) g = 32; // space - glyphs[g]->draw(bearingX[g] + s, -bearingY[g]+height, 0, 1, 1, 0, 0); + glPushMatrix(); + glTranslatef(bearingX[g] + s, -bearingY[g]+height, 0.0f); + glCallList(list+g); + glPopMatrix(); s += spacing[g] * mSpacing; } glPopMatrix(); @@ -81,7 +87,10 @@ namespace opengl void Font::print(char character, float x, float y) const { if (!glyphs[character]) character = ' '; - glyphs[character]->draw(x, y+height, 0, 1, 1, 0, 0); + glPushMatrix(); + glTranslatef(x, y+height, 0.0f); + glCallList(list+character); + glPopMatrix(); } int Font::getWidth(const std::string & line) const diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index be9e55667..4228b312c 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -43,6 +43,7 @@ namespace opengl float lineHeight; float mSpacing; // modifies the spacing by multiplying it with this value Glyph ** glyphs; + GLuint list; // the list of glyphs, for quicker drawing public: static const unsigned int MAX_CHARS = 256; diff --git a/src/modules/graphics/opengl/Glyph.cpp b/src/modules/graphics/opengl/Glyph.cpp index 06f431456..0e61f5aee 100644 --- a/src/modules/graphics/opengl/Glyph.cpp +++ b/src/modules/graphics/opengl/Glyph.cpp @@ -55,31 +55,6 @@ namespace opengl data->release(); unload(); } - - void Glyph::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const - { - static Matrix t; - - t.setTransformation(x, y, angle, sx, sy, ox, oy); - - if(texture != 0) - glBindTexture(GL_TEXTURE_2D,texture); - - glPushMatrix(); - - glMultMatrixf((const GLfloat*)t.getElements()); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x); - glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s); - glDrawArrays(GL_QUADS, 0, 4); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - - glPopMatrix(); - - } bool Glyph::load() { @@ -112,7 +87,15 @@ namespace opengl 0, format, GL_UNSIGNED_BYTE, - data->getData()); + data->getData()); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x); + glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s); + glDrawArrays(GL_QUADS, 0, 4); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); return true; } diff --git a/src/modules/graphics/opengl/Glyph.h b/src/modules/graphics/opengl/Glyph.h index d6c2578c0..43e3c42f5 100644 --- a/src/modules/graphics/opengl/Glyph.h +++ b/src/modules/graphics/opengl/Glyph.h @@ -40,7 +40,7 @@ namespace graphics namespace opengl { - class Glyph : public Drawable, public Volatile + class Glyph : public Volatile { private: @@ -68,8 +68,6 @@ namespace opengl float getWidth() const; float getHeight() const; - void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; - }; // Glyph } // opengl