void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); /*蓝色茶壶*/ glPushMatrix(); glColor3f(0.0,0.0,1.0); glutSolidTeapot(1.5); glPopMatrix(); /*红色立方体*/ glPushMatrix(); glTranslatef(5.0,0.0,0.0);//坐标变换 glColor3f(1.0,0.0,0.0); glutSolidCube(1.0); glPopMatrix(); /*绿色茶壶*/ glPushMatrix(); glTranslatef(-5.0,0.0,0.0);//坐标变换 glColor3f(0.0,1.0,0.0); glutSolidTeapot(1.0); glPopMatrix(); glFlush(); } void myReshape(GLsizei w,GLsizei h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80.0,(GLdouble)w/(GLdouble)h,1.0,20.0);//创建透视投影矩阵 glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-8.0); } |
![]() 图四:三个不重叠的物体 |
![]() 图五:两个茶壶重叠在一起 |