Browse Source

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

Bill Meltsner 15 years ago
parent
commit
34ac035c1b

+ 12 - 3
src/modules/graphics/opengl/Font.cpp

@@ -34,10 +34,13 @@ namespace opengl
 	: height(data->getHeight()), lineHeight(1.25), mSpacing(1)
 	: height(data->getHeight()), lineHeight(1.25), mSpacing(1)
 	{
 	{
 		glyphs = new Glyph*[MAX_CHARS];
 		glyphs = new Glyph*[MAX_CHARS];
+		
 		for(unsigned int i = 0; i < MAX_CHARS; i++)
 		for(unsigned int i = 0; i < MAX_CHARS; i++)
 		{
 		{
 			glyphs[i] = new Glyph(data->getGlyphData(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();
 			widths[i] = data->getGlyphData(i)->getWidth();
 			spacing[i] = data->getGlyphData(i)->getAdvance();
 			spacing[i] = data->getGlyphData(i)->getAdvance();
 			bearingX[i] = data->getGlyphData(i)->getBearingX();
 			bearingX[i] = data->getGlyphData(i)->getBearingX();
@@ -72,7 +75,10 @@ namespace opengl
 		for (unsigned int i = 0; i < text.size(); i++) {
 		for (unsigned int i = 0; i < text.size(); i++) {
 			int g = (int)text[i];
 			int g = (int)text[i];
 			if (!glyphs[g]) g = 32; // space
 			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;
 			s += spacing[g] * mSpacing;
 		}
 		}
 		glPopMatrix();
 		glPopMatrix();
@@ -81,7 +87,10 @@ namespace opengl
 	void Font::print(char character, float x, float y) const
 	void Font::print(char character, float x, float y) const
 	{
 	{
 		if (!glyphs[character]) character = ' ';
 		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
 	int Font::getWidth(const std::string & line) const

+ 1 - 0
src/modules/graphics/opengl/Font.h

@@ -43,6 +43,7 @@ namespace opengl
 		float lineHeight;
 		float lineHeight;
 		float mSpacing; // modifies the spacing by multiplying it with this value
 		float mSpacing; // modifies the spacing by multiplying it with this value
 		Glyph ** glyphs;
 		Glyph ** glyphs;
+		GLuint list; // the list of glyphs, for quicker drawing
 
 
 	public:
 	public:
 		static const unsigned int MAX_CHARS = 256;
 		static const unsigned int MAX_CHARS = 256;

+ 9 - 26
src/modules/graphics/opengl/Glyph.cpp

@@ -55,31 +55,6 @@ namespace opengl
 			data->release();
 			data->release();
 		unload();
 		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()
 	bool Glyph::load()
 	{
 	{
@@ -112,7 +87,15 @@ namespace opengl
 			0, 
 			0, 
 			format, 
 			format, 
 			GL_UNSIGNED_BYTE, 
 			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;
 		return true;
 	}
 	}

+ 1 - 3
src/modules/graphics/opengl/Glyph.h

@@ -40,7 +40,7 @@ namespace graphics
 namespace opengl
 namespace opengl
 {
 {
 	
 	
-	class Glyph : public Drawable, public Volatile
+	class Glyph : public Volatile
 	{
 	{
 	private:
 	private:
 
 
@@ -68,8 +68,6 @@ namespace opengl
 		float getWidth() const;
 		float getWidth() const;
 		float getHeight() const;
 		float getHeight() const;
 
 
-		void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const;
-
 	}; // Glyph
 	}; // Glyph
 	
 	
 } // opengl
 } // opengl