I wish ppl can help explain the code below.
The code is from here, and it works.
The main questions can include the uses of the following functions in order to draw the text.
glGetDoublevglPushMatrixglPopMatrixglLoadMatrixd(matrix)
Why we use them ?
The full code is presented again as below :
void drawText(const char* text, int length, int x, int y) {
glMatrixMode(GL_PROJECTION);
double* matrix = new double[16];
glGetDoublev(GL_PROJECTION_MATRIX, matrix);
glLoadIdentity();
glOrtho(0, 800, 0, 600, -5, 5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glRasterPos2i(x, y);
for (int i=0; i < length; i++) {
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, (int)text[i]);
printf("Hello world!\n");
}
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glLoadMatrixd(matrix);
glMatrixMode(GL_MODELVIEW);
}