stack overflow error from printing text?

Started by
1 comment, last by sd_dracula 16 years, 11 months ago
whenever i use this function to draw text on the screen i get a lot of stack overflow errors in the console window. it doesnt crash but i think if i leave it running long enough it does. char pixelstring[30]; void printText(const char* text, int s, float x, float y, float z) { sprintf(pixelstring, text, s); //Print a string to the screen glPushMatrix(); glDisable(GL_LIGHTING); glColor4f(1.0,1.0,0.0,1.0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, 200, 0, 200); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // render the string renderBitmapString(x,y,z,GLUT_BITMAP_TIMES_ROMAN_24,pixelstring); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } void renderBitmapString(float x, float y, float z, void *font, char *string) { char *c; glRasterPos3f(x, y,z); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } } and then i call this inside the display funciton of glut printText("SCORE: %d",score,0,0,0); can anyone see a problem there?
Advertisement
The answer is very simple: You got 3 glPushMatrix but only 2 glPopMatrix so this causes a stack overflow
http://3d.benjamin-thaut.de
hehe thanks.
i knew it was something simple that i couldn't see :D

This topic is closed to new replies.

Advertisement