这段程序就是画了一个三角形,想让键盘控制它来上下左右运动,但是无论怎么钦按钮他都不运动,非常郁闷,请求支援。谢谢
#include <stdlib.h>
#include <gl/glut.h>
#include <windows.h>
static GLfloat x=0.0;
static GLfloat y=0.0;
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.2f,0.8f,0.6f);
glBegin(GL_TRIANGLES);
glVertex2f(0.0+x,0.0+y);
glVertex2f(0.5+x,0.0+y);
glVertex2f(0.5+x,0.5+y);
glEnd();
glutSwapBuffers();
glFlush();
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 'd':
case 'D':
x+=0.1;
if(x>0.5)
x=0.5;
glutPostRedisplay();
break;
case 'a':
case 'A':
x-=0.1;
if(x<-1.0)
x=-1.0;
glutPostRedisplay();
break;
case 'w':
case 'W':
y+=0.1;
if(y>0.5)
y=0.5;
glutPostRedisplay();
break;
case 's':
case 'S':
y-=0.1;
if(y<-1.0)
y=-1.0;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}
void reshape(int w,int h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
posted on 2008-10-16 21:08
正牌的天地之灵和他的徒儿们肖赫_王婷婷_王冠_郑燚_孙婷 阅读(150)
评论(0) 编辑 收藏 引用 所属分类:
risky