2014年4月24日 星期四

鍵盤控制圖形

#include <GL/glut.h>
float teapotX=0, teapotY=0;
void keyboard(unsigned char key, int x,int y)
{
if(key == 'a') teapotX+=0.1;
if(key == 'b') teapotX-=0.1;
if(key == 'c') teapotY+=0.1;
if(key == 'd') teapotY-=0.1;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX ,teapotY, 0);
glutSolidTeapot(0.4);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

glutMainLoop();
}


沒有留言:

張貼留言