# This program demonstrates how multiple transformations accumulate # An un-transformed triangle is drawn, followed by one with a # translation, followed by another with one more translation, # which is added to the first import sys from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * def draw(): glLoadIdentity() glClear(GL_COLOR_BUFFER_BIT) glColor3f(0, 0, 1) glBegin(GL_TRIANGLES) glVertex2f(0.0, 0.0) glVertex2f(0.5, 0.0) glVertex2f(0.25, 0.5) glEnd() glTranslatef(0.25, 0.25, 0.0) glColor3f(0, 1, 0) glBegin(GL_TRIANGLES) glVertex2f(0.0, 0.0) glVertex2f(0.5, 0.0) glVertex2f(0.25, 0.5) glEnd() glTranslatef(-0.25, -1.0, 0.0) glColor3f(1, 0, 0) glBegin(GL_TRIANGLES) glVertex2f(0.0, 0.0) glVertex2f(0.5, 0.0) glVertex2f(0.25, 0.5) glEnd() glFlush() def keyboard(key, x, y): if key == chr(27): sys.exit(0) glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(300, 300) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutMainLoop()