264 Introduction to C++ Programming and Graphics
glColor3f(0.0f,0.0f,0.0f);
glTranslatef(0.1, 0.10, 0.18);
glutSolidSphere(0.05,10,10);
glTranslatef(-0.2, 0.0, 0.0);
glutSolidSphere(0.05,10,10);
glPopMatrix();
//--- Nose:
glColor3f(1.0, 0.5 , 0.5);
glRotatef(0.0, 1.0, 0.0, 0.0);
glutSolidCone(0.08, 0.5, 10,2);
glFlush();
}
A transformation matrix can be temporary of permanent. In the first
case, the old transformation matrix can be saved to be reinstated at a later time.
TheglPushMatrixfunction saves the current settings, and theglPopMatrix
function reinstates the settings. Thesnowmancode shows that these functions
simplify the geometrical construction by allowing us to work in temporary coor-
dinates that are properly translated or rotated with respect to fixed coordinates.
When we are done, we revert to the original world coordinates.
Printing text on the screen
The following function contained in the filetheend.ccprints a character
array on the screen:
void write()
{
glClear(GLCOLORBUFFERBIT);
char protasi[] = "The Beginning";
int x=35, y=50;
int len, i;
glRasterPos2i(x, y);
len = (int) strlen(protasi);
for (i=0; i<len; i++)
{
glutBitmapCharacter(GLUTBITMAPHELVETICA18, protasi[i]);
}
glFlush();
}