|
|
发表于 2005-12-30 14:37:00
|
显示全部楼层
Re:为什么不能连续转动?
#include "GL/glut.h"
#pragma comment( lib, "glut32.lib")
static GLfloat rotateAngle = 0.0;
void TimeFun(int n);
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glutTimerFunc(10,TimeFun,0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glTranslatef(0.0, 0.0, -5.0);
glRotatef(rotateAngle, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0);
glutWireCube(1.0);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void TimeFun(int n)
{
rotateAngle += 3.0;
if(rotateAngle > 360)
rotateAngle -= 360;
display();
glutTimerFunc(10,TimeFun,0);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
|
|