254 Introduction to C++ Programming and Graphics
glutCreateWindow("GLUT window");
glClearColor(0.8,0.5,0.2,1.0);
glutDisplayFunc(blank);
glutMainLoop();
return 0;
}
//-- function blank
void blank()
{
glClear(GLCOLORBUFFERBIT);
}
The code makes severalGlut(glut) and OpenGL (gl) calls according to a very
specific protocol:
- The first command in the main program calls theGlutfunction:
glutInit(int &argc, char **argv);
This function parses the window-specific parameters transmitted to the
X11 server. Note that the first argument is the integer pointer, &argc.
- The last command in the main program calls the function:
glutMainLoop();
which launches the graphics display in an infinite loop that can be inter-
rupted only by certain events.
In OpenGL and GLUT programming, we first register the callbacks (graph-
ics functions), then define the graphics object, and finally launch the
graphics display by entering the main loop.If we do not enter the main
loop, nothing will happen.
- The second command in the main program generates a graphics window
and defines the title. - The third command in the main program sets the background color painted
when the window is cleared in the default RBGA mode. - The fourth command in the main program calls the function:
glutDisplayFunc(char functionname);
This function launches the user-defined function stated in the argument.