2014年4月25日 星期五

Week 10 , 用鍵盤控制茶壺

#include <GL/glut.h>
#include <stdio.h>
float angle=0;
void keyboard(unsigned char key , int x , int y)
{
     printf("%c %d %d\n",key,x,y);
     if(key=='a') angle+=3;
     if(key=='b') angle-=3;
     glutPostRedisplay();
   
     //glutSwapBuffers();
}
void display()
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
     glPushMatrix();
        glRotatef(angle,0,1,0);
        glutSolidTeapot(0.3);
     glPopMatrix();
     glutSwapBuffers();
}
int main()
{
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 10");
 
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
 
    glutMainLoop();
}

注 : 專案 ---> 專案選項 ---- > Win32Console ---> 確定

沒有留言:

張貼留言