Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLUT pop-up menus

Tags:

opengl

menu

glut

Is it easy to create GLUT pop-up menus for my OpenGL application? If yes, how?

like image 528
Ashwin Nanjappa Avatar asked Aug 18 '08 09:08

Ashwin Nanjappa


1 Answers

Creating and using pop-up menus with GLUT is very simple. Here is a code sample that creates a pop-up menu with 4 options:

// 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;
}
like image 196
Ashwin Nanjappa Avatar answered Oct 18 '22 08:10

Ashwin Nanjappa