# Example of all GLUT geometry functions # # Dave Pape # 27 September 2004 import sys from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * viewRotY = 0 viewRotX = 0 def draw(): glClear(GL_COLOR_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-15, 15, -15, 15, -10, 10) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glRotatef(viewRotX, 1.0, 0.0, 0.0) glRotatef(viewRotY, 0.0, 1.0, 0.0) glColor3f(1.0, 1.0, 1.0) glPushMatrix() glTranslatef(-12.0, 0.0, 0.0) glutSolidSphere(1.5, 16, 8) glTranslatef(0.0, 4.0, 0.0) glutWireSphere(1.5, 40, 8) glPopMatrix() glColor3f(1.0, 1.0, 0.0) glPushMatrix() glTranslatef(-8.0, 0.0, 0.0) glutSolidCube(2.0) glTranslatef(0.0, 4.0, 0.0) glutWireCube(2.0) glPopMatrix() glColor3f(0.0, 1.0, 1.0) glPushMatrix() glTranslatef(-4.0, 0.0, 0.0) glutSolidCone(1.0, 1.5, 16, 4) glTranslatef(0.0, 4.0, 0.0) glutWireCone(1.0, 1.5, 16, 4) glPopMatrix() glColor3f(0.0, 1.0, 0.0) glPushMatrix() glTranslatef(0.0, 0.0, 0.0) glutSolidTorus(0.5, 1.5, 8, 16) glTranslatef(0.0, 4.0, 0.0) glutWireTorus(0.5, 1.5, 8, 16) glPopMatrix() glColor3f(1.0, 0.0, 1.0) glPushMatrix() glTranslatef(4.0, 0.0, 0.0) glutSolidDodecahedron() glTranslatef(0.0, 4.0, 0.0) glutWireDodecahedron() glPopMatrix() glColor3f(1.0, 0.0, 0.0) glPushMatrix() glTranslatef(8.0, 0.0, 0.0) glutSolidOctahedron() glTranslatef(0.0, 4.0, 0.0) glutWireOctahedron() glPopMatrix() glColor3f(0.0, 0.0, 1.0) glPushMatrix() glTranslatef(12.0, 0.0, 0.0) glutSolidTetrahedron() glTranslatef(0.0, 4.0, 0.0) glutWireTetrahedron() glPopMatrix() glColor3f(1.0, 1.0, 0.0) glPushMatrix() glTranslatef(-6.0, -4.0, 0.0) glutSolidIcosahedron() glTranslatef(0.0, -4.0, 0.0) glutWireIcosahedron() glPopMatrix() glColor3f(1.0, 0.0, 0.0) glPushMatrix() glTranslatef(6.0, -4.0, 0.0) glutSolidTeapot(2.0) glTranslatef(0.0, -4.0, 0.0) glutWireTeapot(2.0) glPopMatrix() glutSwapBuffers() def keyboard(key, x, y): if key == chr(27): sys.exit(0) def specialkey(key,x,y): global viewRotX, viewRotY if key == GLUT_KEY_LEFT: viewRotY = viewRotY + 3 elif key == GLUT_KEY_RIGHT: viewRotY = viewRotY - 3 elif key == GLUT_KEY_UP: viewRotX = viewRotX + 3 elif key == GLUT_KEY_DOWN: viewRotX = viewRotX - 3 glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowSize(400,400) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutSpecialFunc(specialkey) glutMainLoop()