创建GLUT弹出菜单,是否易于应用到我的OpenGL程序中?如果是,怎么做?
使用GLUT创建和使用弹出菜单非常简单。下面是一个创建具有4个选项的弹出菜单的代码示例:
// Create menu
int menu = glutCreateMenu(menuCallback);
glutAddMenuEntry("Option 1", 1);
glutAddMenuEntry("Option 2", 2);
glutAddMenuEntry("Option 3", 3);
glutAddMenuEntry("Option 4", 4);
// Attach menu to right mouse button
glutAttachMenu(GLUT_RIGHT_BUTTON);
// Menu items
enum MENU_TYPE
{
MENU_FRONT,
MENU_SPOT,
MENU_BACK,
MENU_BACK_FRONT,
};
// Assign a default value
MENU_TYPE show = MENU_BACK_FRONT;
// Menu handling function declaration
void menu(int);
int main()
{
// ...
// Create a menu
glutCreateMenu(menu);
// Add menu items
glutAddMenuEntry("Show Front", MENU_FRONT);
glutAddMenuEntry("Show Back", MENU_BACK);
glutAddMenuEntry("Spotlight", MENU_SPOT);
glutAddMenuEntry("Blend 'em all", MENU_BACK_FRONT);
// Associate a mouse button with menu
glutAttachMenu(GLUT_RIGHT_BUTTON);
// ...
return;
}
// Menu handling function definition
void menu(int item)
{
switch (item)
{
case MENU_FRONT:
case MENU_SPOT:
case MENU_DEPTH:
case MENU_BACK:
case MENU_BACK_FRONT:
{
show = (MENU_TYPE) item;
}
break;
default:
{ /* Nothing */ }
break;
}
glutPostRedisplay();
return;
}