tags:

views:

1011

answers:

2
+3  Q: 

GLUT pop-up menus

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

+4  A: 

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;
}
Ashwin
You sound like you knew this all a long...
thyrgle
A: 

@Michał Piaskowski: It's (currently) not possible to accept your own answers.

Rob Thomas
It should be made possible to answer your own, but with no credit. Or maybe you would get no credit till someone else votes for the question. You just don't want people writing and answering tons of useless questions like "What is C?" in order to build up rep.
Baxissimo