[译]GLUT教程 - 交换菜单

Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Swapping Menus

 

GLUT甚至可以在应用程序过程中更改整个菜单.提供了两个函数: glutSetMenu和glutGetMenu.原型如下:

 

void glutSetMenu(int menu);

menu - 上一个创建菜单的索引值

该函数可以让我们切换菜单,例如在应用程序上下文中切换.

 

int glutGetMenu(void);

 

该函数返回当前菜单的索引值.下面我们演示用户按F1时在两个菜单之间切换.

void processSpecialKeys(int c, int x, int y) {



    if (!flag) {

        if (c == GLUT_KEY_F1) {

            int x = glutGetMenu();

            if (x == menu1)

                glutSetMenu(menu2);

            else

                glutSetMenu(menu1);

            // don't forget to attach the menu!!!

            glutAttachMenu(GLUT_RIGHT_BUTTON);

        }

    }

}



void createGLUTMenus() {



    menu2 = glutCreateMenu(processMenuEvents);

    glutAddMenuEntry("Blue",BLUE);

    glutAddMenuEntry("Green",GREEN);

    glutAddMenuEntry("Red",RED);



    menu1 = glutCreateMenu(processMenuEvents);

    glutAddMenuEntry("Red",RED);

    glutAddMenuEntry("Green",GREEN);

    glutAddMenuEntry("Blue",BLUE);

    glutAttachMenu(GLUT_RIGHT_BUTTON);

}

 

你可能感兴趣的:(教程)