右键菜单

#include <gl/glut.h>
#include <stdio.h>
int mainMenu,subMenu1,subMenu2;

void myDisplay(void)
{
    glClearColor(0.0,0.0,1.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);
    glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);//void glOrtho(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,GLdouble near,GLdouble far)
                                        //创建一个正交平行的视景体。 一般用于物体不会因为离屏幕的远近而产生大小的变换的情况
    glBegin(GL_POLYGON);
    glVertex2f(-0.5,-0.5);
    glVertex2f(-0.5,0.5);
    glVertex2f(0.5,0.5);
    glVertex2f(0.5,-0.5);
    glEnd();
    glutSwapBuffers();
}



void GetCurrentMenu(void)
{
    int nMenu;
    nMenu=glutGetMenu();
    if(nMenu==mainMenu)
        printf("The current menu is mainMenu./n");
    if(nMenu==subMenu1)
        printf("The current menu is subMenu1./n");
    if(nMenu==subMenu2)
        printf("The current menu is subMenu2./n");
}

void SubMenuFunc1(int data)
{
    GetCurrentMenu();
    switch(data)
    {
    case 1:
        printf("subMenu1's item 1 is triggered./n");
        break;
    case 2:
        printf("subMenu1's item 2 is triggered./n");
        break;
    case 3:
        printf("subMenu1's item 3 is triggered./n");
        break;
    }
}

void SubMenuFunc2(int data)
{
    GetCurrentMenu();
    switch(data)
    {
    case 1:
        printf("subMenu2's item 1 is triggered./n");
        break;
    case 2:
        printf("subMenu2's item 2 is triggered./n");
        break;
    case 3:
        printf("subMenu2's item 3 is triggered./n");
        break;
    }
}

void MenuFunc(int data)
{
    GetCurrentMenu();
    switch(data)
    {
    case 1:
        printf("mainMenu's item 1 is triggered./n");
        break;
    case 2:
        printf("mainMenu's item 2 is triggered./n");
        break;
    case 3:
        printf("mainMenu's item 3 is triggered./n");
        break;
    }
}

int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
    glutInitWindowSize(500,400);
    glutInitWindowPosition(100,100);
    glutCreateWindow("Menu");
    glutDisplayFunc(myDisplay);

    subMenu1=glutCreateMenu(SubMenuFunc1);
    glutAddMenuEntry("subMenu1's item",1);
    glutAddMenuEntry("subMenu1's item",2);
    glutAddMenuEntry("subMenu1's item",3);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    subMenu2=glutCreateMenu(SubMenuFunc2);
    glutAddMenuEntry("subMenu2's item1",1);
    glutAddMenuEntry("subMenu2's item2",2);
    glutAddMenuEntry("subMenu2's item3",3);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
   
    mainMenu=glutCreateMenu(MenuFunc);
    glutAddSubMenu("subMenu1",subMenu1);
    glutAddSubMenu("subMenu2",subMenu2);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    glutAddMenuEntry("Item1",1);
    glutAddMenuEntry("Item2",2);
    glutAddMenuEntry("Item3",3);
   
    glutMainLoop();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值