Help end child hunger

Sub Menus

Prev: Popup Menus Next: Modifying a Menu

In the previous section we saw how to build a simple menu, and process the events generated by a user selection. Now we’re going to see how to add a cascade submenu.

A submenu is created with the same function as a menu. Therefore we use the function glutCreateMenu, see the previous section, to create submenus as well as menus. Then we must add the submenu as an entry to the menu. This is done in GLUT using glutAddSubMenu.

void glutAddSubMenu(char *entryName, int menuIndex);


  • entryName – The name of the submenu entry in the menu
  • menuIndex – The index of the submenu, this is the value that we get as a return value when calling glutCreateMenu for the submenu.

This function adds an entry to the end of the menu. When selected, the new entry will open a submenu.

The following piece of code illustrates the usage of the above function:

void createPopupMenus() {

	shrinkMenu = glutCreateMenu(processShrinkMenu);

	fillMenu = glutCreateMenu(processFillMenu);

	colorMenu = glutCreateMenu(processColorMenu);

	mainMenu = glutCreateMenu(processMainMenu);
	glutAddSubMenu("Polygon Mode", fillMenu);
	glutAddSubMenu("Color", colorMenu);

	// attach the menu to the right button

Using the code above, when the user pressed the right mouse button a menu with two options would be presented: “Polygon Mode” and “Color”. Pressing on “Color”, a submenu appears with three items: “Red”, “Blue”, “Green”, and “Orange”.



Prev: Popup Menus Next: Modifying a Menu

Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 Suffusion theme by Sayontan Sinha