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
glEnable(GL_TEXTURE_2D);
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__);
return;
}
charCount++;
glPushMatrix();
{
glTranslatef(p->pos.x, p->pos.y, p->pos.z);
glRotatef(p->angle, 0, 0, 1);
myDrawChar(p->character-33, 0, 0);
}
glPopMatrix();
}
//-----------------------------------------------------------
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 );
}
}