#include <gl/glut.h>
GLfloat X=10.0f;
GLfloat Y=1.0f;
GLfloat Z=5.0f;
GLfloat diffuse[]={0.7,0.7,0.0,1.0};
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glPushMatrix();
glRotatef(X,1.0,0.0,0.0);
glRotatef(Y,0.0,1.0,0.0);
glRotatef(Z,0.0,0.0,1.0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
glutSolidCube(1.0);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myReshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.5,1.5,-1.5,1.5);
if(w <= h)
glOrtho(-2.25,2.25,-2.25*h/w,2.25*h/w,-10.0,10.0);
else
glOrtho(-2.25*w/h,2.25*w/h,-2.25,2.25,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void myAnimate(void)
{
X+=1.0;
Y+=1.0;
Z+=1.0;
glutPostRedisplay();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(400,400);
glutInitWindowPosition(200,200);
glutCreateWindow("color");
glutReshapeFunc(myReshape);
glutDisplayFunc(myDisplay);
glutIdleFunc(myAnimate);//此函数设置全局空闲回调函数。,从而使GLUT程序可以执行后台任务或连续动画
glutMainLoop();
return 0;
}
旋转的立方体
最新推荐文章于 2024-05-13 08:00:00 发布