GLUT Context Menus & Submenus
Understanding dynamic menu registrations, attachment hooks, and submenus.
Context Menu Hook
GLUT allows creating floating pop-up context menus bound to mouse buttons. The creation and attachment sequence follows:
int menuId = glutCreateMenu(myMenuHandler);
glutAddMenuEntry("Red Color", 1);
glutAddMenuEntry("Blue Color", 2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
When the user clicks the attached button (typically GLUT_RIGHT_BUTTON), a menu pops up, and selecting an entry triggers myMenuHandler(optionId).
Hierarchical Submenus
GLUT supports multiple submenus. You can build nested layouts by creating a menu, registering entries, and then adding it as a submenu item in a parent menu structure:
int colorSubmenu = glutCreateMenu(myMenuHandler);
glutAddMenuEntry("Red", 1);
glutAddMenuEntry("Blue", 2);
glutCreateMenu(myMenuHandler);
glutAddSubMenu("Material Color", colorSubmenu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
Ready to Build Custom Menus?
Launch our interactive visualizer to add menu entries dynamically and test custom right-click menus.
Launch Menus Visualizer →