- 29.00 KB
- 2022-08-30 发布
- 1、本文档由用户上传,淘文库整理发布,可阅读全部内容。
- 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,请立即联系网站客服。
- 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细阅读内容确认后进行付费下载。
- 网站客服QQ:403074932
#includestaticGLfloatxRot=0.0f;staticGLfloatyRot=0.0f;voidReshape(intw,inth){glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glClearColor(0.5f,0.5f,1.0f,0.5f);GLfloatScale;if(h==0)h=1;glViewport(0,0,w,h);Scale=(GLfloat)w/(GLfloat)h;glMatrixMode(GL_PROJECTION);glLoadIdentity()gluPerspective(40.0f,Scale,1.0,40.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}voidSpecialKeys(intkey,intx,inty){if(key==GLUT_KEY_UP)xRot-=1.0f;if(key==GLUT_KEY_DOWN)xRot+=1.0f;if(key==GLUT_KEY_LEFT)yRot-=1.0f;if(key==GLUT_KEY_RIGHT)\nyRot+=1.0f;xRot=(GLfloat)((constint)xRot%360);yRot=(GLfloat)((constint)yRot%360);glutPostRedisplay();}voidDisplay(void){GLUquadricObj*pObj;glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glPushMatrix();glTranslatef(0.0f,-1.0f,-5.0f);glRotatef(xRot,1.0f,0.0f,0.0f);glRotatef(yRot,0.0f,1.0f,0.0f);pObj=gluNewQuadric();gluQuadricNormals(pObj,GLU_SMOOTH);//MainBodyglPushMatrix();glColor3f(1.0f,1.0f,1.0f);gluSphere(pObj,.40f,26,13);//BottomglTranslatef(0.0f,.550f,0.0f);//MidsectiongluSphere(pObj,.3f,26,13);glTranslatef(0.0f,0.45f,0.0f);//HeadgluSphere(pObj,0.24f,26,13);//EyesglColor3f(0.0f,0.0f,0.0f);glTranslatef(0.1f,0.1f,0.21f);gluSphere(pObj,0.02f,26,13);glTranslatef(-0.2f,0.0f,0.0f);gluSphere(pObj,0.02f,26,13);//NoseglColor3f(1.0f,0.3f,0.3f);glTranslatef(0.1f,-0.12f,0.0f);gluCylinder(pObj,0.04f,0.0f,0.3f,26,13);glPopMatrix();\n//HatglPushMatrix();glColor3f(0.0f,0.0f,0.0f);glTranslatef(0.0f,1.17f,0.0f);glRotatef(-90.0f,1.0f,0.0f,0.0f);gluCylinder(pObj,0.17f,0.17f,0.4f,26,13);//HatbrimglDisable(GL_CULL_FACE);gluDisk(pObj,0.17f,0.28f,26,13);glEnable(GL_CULL_FACE);glTranslatef(0.0f,0.0f,0.40f);gluDisk(pObj,0.0f,0.17f,26,13);glPopMatrix();glPopMatrix();glutSwapBuffers();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutInitWindowSize(800,600);glutCreateWindow("Snowman");glutReshapeFunc(Reshape);glutSpecialFunc(SpecialKeys);glutDisplayFunc(Display);glutMainLoop();return0;}