I have a game that I want to be able to center text in. The only problem is that the way I thought would work just makes my game stop responding. I don’t know of any other way to center it efficiently without having to count the characters in each string. here is my code hopefully you can figure it out.
void renderBitmapString(float x,float y,float z,char *string, int center) {
char *c;
char *b;
int amount=0;
for(b=string;b!=’\0’;b++)
amount++;
if(center == 1)
glRasterPos3f(x-amount/2, y,z);
else
glRasterPos3f(x, y,z);
for (c=string; *c != ‘\0’; c++) {
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *c);
}
}