8.4 GUI programming withGlui 281
glutAddMenuEntry("Quit", 0); // Create an entry
glutAttachMenu(GLUTLEFTBUTTON);// respond to the left mouse button
glutAttachMenu(GLUTRIGHTBUTTON);// respond to the right mouse button
}
//--- menu:
void menu(int value)
{
glClear(GLCOLORBUFFERBIT);
if(value == 0)
{
glutDestroyWindow(win);
exit(0);
}
else
{
drawflag=value;
}
}
Figure 8.3.1 shows the produced graphics window, including a drop-down
menu generated by the user-defined functionshowmenu, which calls in turn
the user-defined functionmenu. Each of these functions makes OpenGL and
Glutcalls. TheglutCreateMenu(menu)call returns to themenufunction an
integer mapping the menu items determined by theglutAddMenuEntrycalls.
Problems
8.3.1. Modify theglutmenu.cccode to show the triangle at the initial display.
8.3.2. Modify theglutmenu.cccode to include the drawing of a rectangle as
a third option.
8.3.3. Modify theglutmenu.cccode to incorporate a second sub-menu orig-
inating from the triangle that offers the option for a red or yellow color.
8.4 GUI programming with GLUI....................
We have learned how to program graphics based on theGlutlibrary using
OpenGL functions. To build a professional application incorporating a graph-
ical user interface (GUI), we need further toolboxes offeringwidgets. The dic-
tionary defines a widget as a contraption, a contrivance, a gadget, or a gizmo.
In software engineering, widgets are programmed as objects of a drawing class.