256 Introduction to C++ Programming and Graphics
In this case, the invoked functionblankclears the screen to the color set
by the third command in the main program.
The blank-screen code will be our basic template for developing further appli-
cations.
Teap ot
The following C++ code contained in the fileglutshapes.ccconsists of
the main program and the user-defined functionshowme. The code opens a
window and draws the wire-frame image of a teapot:
#include <freeglut.h>
using namespace std;
void disp(void);
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUTDEPTH|GLUTSINGLE|GLUTRGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glOrtho(-1.2, 1.2, -1.2, 1.2, -1.2, 1.2);
glutCreateWindow("Teapot");
glutDisplayFunc(showme);
glClearColor(0.2,0.5,0.2,0.2);
glutMainLoop();
return 0;
}
//--- showme
void showme(void)
{
glClear(GLCOLORBUFFERBIT); // clear the screen
glutWireTeapot(0.6);
}
The graphics output of the code on the desktop is shown in Figure 8.1.1(b).
Three newGlutfunctions have been introduced to set the display mode and
specify the location and size of the graphics window:
glutInitDisplayMode
glutInitWindowPosition
glutInitWindowSize
In addition, the OpenGL functionglOrthowas invoked to set the lower and