/* * This function puts letters on the OpenGL window * Usage of the parameters are specified as follows: * x: the start x position of the text, range = -1 ~ +1 * y: the start y position of the text, range = -1 ~ +1 * text: char array that you want it to be showed on the screen * font: specified in glut.h line 307~317 * GLUT_BITMAP_9_BY_15 * GLUT_BITMAP_8_BY_13 * GLUT_BITMAP_TIMES_ROMAN_10 * GLUT_BITMAP_TIMES_ROMAN_24 * GLUT_BITMAP_HELVETICA_10 * GLUT_BITMAP_HELVETICA_12 * GLUT_BITMAP_HELVETICA_18 * r, g, b, a : the color of the text */ void myGlPutText(float x, float y, char* text, LPVOID font, float r, float g, float b, float a) { if(!text || !strlen(text)) return; /* Projectoin and Modelview Matrix store then clear */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); /* blending and lighting status storing then swap to text putting mode */ bool blending = false; if(glIsEnabled(GL_BLEND)) blending = true; else glEnable(GL_BLEND); bool lighting = true; if(glIsEnabled(GL_LIGHTING)) glDisable(GL_LIGHTING); else lighting = false; /* Start to put text */ glColor4f(r,g,b,a); glRasterPos2f(x,y); while (*text) { glutBitmapCharacter(font, *text); text++; } /* blending and lighting status resume */ if(!blending) glDisable(GL_BLEND); if(lighting) glEnable(GL_LIGHTING); /* Projectoin and Modelview Matrix restore */ glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }