drawing lots of text

Hi All!

I’ve got a project where I have to draw a lot of text to the screen (about 12,000) characters. I’ve been using a hacked version of ofTrueTypeFont to save pushing and popping GL_TEXTURE_2D and a few other little things. However, it’s still running pretty slow. I’m not sure how to go about this.

Any suggestions of how I can get the speed up?

Would it be faster to render all the text to a single texture, then send a vertex array all in one go?



to test what’s making it slow, can you try drawing 12,000 textures (either ofTextures or ofImages) to see if that drawing that many objects is slowing you down.

the ofTrueTypeFont has some push and pop attributes for transparency (since it requires transparency). You might see if that’s making it slow (you can be pushing and popping per character).

otherwise, if you post up a sample code, I’d be happy to take a look.

take care,

Below is where the action is. I moved the glEnable/Disable(GL_TEXTURE_2D) and alpha outside this loop, so it only gets called once a frame.

Is there anything I can cache, or call once at the beginning of the loop? I just tried pulling out
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnableClientState( GL_VERTEX_ARRAY );

to the outside of the loop and it seems to have earnt me a couple of FPS.

	void draw(CharParticle *p) {  
		if(p->character==' ' || p->character=='\n') return;  
		if(p->pos.x<-20 || p->pos.x-20>WIDTH || p->pos.y<0 || p->pos.y-80>HEIGHT) return;  
		if (p->character-33 >= nCharacters){  
			//ofLog(OF_LOG_ERROR,"Error : char (%i) not allocated -- line %d in %s", (c + NUM_CHARACTER_TO_START), __LINE__,__FILE__);  
			glTranslatef(p->pos.x, p->pos.y, p->pos.z);  
			glRotatef(p->angle, 0, 0, 1);  
			myDrawChar(p->character-33, 0, 0);  
	void myDrawChar(int c, float x, float y) {  
		int cu = c;  
		GLint height	= cps[cu].height;  
		GLint bwidth	= cps[cu].width;  
		GLint top		= cps[cu].topExtent - cps[cu].height;  
		GLint lextent	= cps[cu].leftExtent;  
		GLfloat	x1, y1, x2, y2, corr, stretch;  
		GLfloat t1, v1, t2, v2;  
		//this accounts for the fact that we are showing 2*visibleBorder extra pixels  
		//so we make the size of each char that many pixels bigger  
		stretch = (float)(visibleBorder * 2);  
		t2		= cps[cu].xOff;  
		v2		= cps[cu].yOff;  
		t1		= cps[cu].tTex + t2;  
		v1		= cps[cu].vTex + v2;  
		corr	= (float)(( (fontSize - height) + top) - fontSize);  
		x1		= lextent + bwidth + stretch;  
		y1		= height + corr + stretch;  
		x2		= (float) lextent;  
		y2		= -top + corr;  
		if (glIsTexture(texNames[cu])) {  
			glBindTexture(GL_TEXTURE_2D, texNames[cu]);  
			glNormal3f(0, 0, 1);  
			GLfloat verts[] = { x2,y2,  
				x2, y1,  
				x1, y1,  
				x1, y2 };  
			GLfloat tex_coords[] = { t2, v2,  
				t2, v1,  
				t1, v1,  
				t1, v2 };  
			//glEnableClientState( GL_TEXTURE_COORD_ARRAY );  
			glTexCoordPointer(2, GL_FLOAT, 0, tex_coords );  
			//glEnableClientState( GL_VERTEX_ARRAY );  
			glVertexPointer(2, GL_FLOAT, 0, verts );  
			glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );  
			//glDisableClientState( GL_TEXTURE_COORD_ARRAY );