converted Font drawing to use display lists - should increase draw speed

This commit is contained in:
Bill Meltsner
2010-08-23 21:24:16 -05:00
parent c06d5c3263
commit 34ac035c1b
4 changed files with 23 additions and 32 deletions
+12 -3
View File
@@ -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
+1
View File
@@ -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;
+9 -26
View File
@@ -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;
}
+1 -3
View File
@@ -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