zoukankan      html  css  js  c++  java
  • coder

    #include <iostream>
    #include <GL/glut.h>
    using std::cout;
    using std::endl;
    float windowWidth=0;
    float windowHeight=0;
    float curX=0.0;
    float curY=0.0;
    void display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(1.0,1.0,1.0);

        glBegin(GL_POLYGON);
        glVertex3f(curX,curY,0.0);
        glVertex3f(curX+50,curY,0.0);
        glVertex3f(curX+50,curY+50,0.0);
        glVertex3f(curX,curY+50,0.0);
        glEnd();

    //    glutSwapBuffers();
        glFlush();
    }
    void reshape(int w,int h)
    {
        windowWidth=(float)w;
        windowHeight=(float)h;
        cout<<"cur width is :"<<w<<endl;
        cout<<"cur height is :"<<h<<endl;
        glViewport(0,0,(GLsizei)w,(GLsizei)h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0,(float)w,0.0,(float)h,-1.0,1.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    void keyboard(unsigned char key, int x, int y)
    {
        cout<<"you pressed the key is :"<<key<<endl;
        switch(key)
        {
        case 'w':
            curY+=20;
            break;
        case 's':
            curY-=20;
            break;
        case 'a':
            curX-=20;
            break;
        case 'd':
            curX+=20;
            break;
        default:
            break;
        }
        if(key=='q'||key=='Q')
            exit(0);
        glutPostRedisplay();
    }
    void motion(int x, int y)
    {
        cout<<"mouse position :"<< "("<<x<<","<<y<<")"<<endl;
        curX=(float)x;
        curY=(float)(windowHeight-y);
        glutPostRedisplay();
    }
    void mouse(int button,int state,int x,int y)
    {
        cout<<"come here yet"<<endl;
        switch(button)
        {
        case GLUT_LEFT_BUTTON:
            if(state==GLUT_DOWN)
                glutFullScreen();
            break;
        case GLUT_RIGHT_BUTTON:
            if(state==GLUT_DOWN)
            {
                glutInitWindowSize(800,600);
                glutInitWindowPosition(0.0,0.0);
            }
            break;
        default:
            break;
        }
        glutPostRedisplay();
    }
    void idler()
    {
        cout<<"i am a idle"<<endl;
    }
    void init()
    {
        glClearColor(0.0,0.0,0.0,0.0);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-300.0,300.0,-300.0,300.0,-1.0,1.0);
    }
    int main(int argc,char **argv)
    {
        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
        glutInitWindowSize(250,250);
        glutInitWindowPosition(0.0,0.0);
        glutCreateWindow("hello,gl Master");
    //    glutFullScreen();
        init();
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutKeyboardFunc(keyboard);
        glutMotionFunc(motion);
        glutMouseFunc(mouse);
        //  glutIdleFunc(idler);
        glutMainLoop();
        return 0;
    }

    生活的残酷,让我们习惯了忘记疲倦,一直奔向远方,追寻着自己的梦想。
  • 相关阅读:
    关于Windows版本的redis启动报错:Creating Server TCP listening socket 127.0.0.1:6379: bind: No error
    03 验证线程是数据共享的
    01 线程的两种创建方式
    33 线程的创建 验证线程之间数据共享 守护线程
    10 进程池的回调函数
    09 进程池的异步方法
    07 进程池的同步方法和异步方法
    08 进程池同步方法
    05 进程池map方法
    06 测试多进程的时间
  • 原文地址:https://www.cnblogs.com/L-Arikes/p/4678678.html
Copyright © 2011-2022 走看看