from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * import sys def display(): global mode glClearColor(0,0,0,0) glClear(GL_COLOR_BUFFER_BIT) glBegin(mode) glVertex2f(0.0,0.7) glColor3f(1.0,0.0,0.0) glVertex2f(-0.6,0.1) glColor3f(0.0,1.0,0.0) glVertex2f(-0.3,-0.2) glColor3f(0.0,0.0,1.0) glVertex2f(0.1,-0.3) glColor3f(1.0,1.0,0.0) glVertex2f(0.6,-0.1) glColor3f(0.0,1.0,1.0) glVertex2f(0.5,0.3) glColor3f(1.0,0.0,1.0) glEnd() glFlush() def clavier(*args): global mode if args[0] == 'q': sys.exit() elif args[0] == 'a': mode = GL_TRIANGLES elif args[0] == 'z': mode = GL_TRIANGLE_STRIP elif args[0] == 'e': mode = GL_TRIANGLE_FAN elif args[0] == 'r': mode = GL_POINTS glutPostRedisplay() def main(): global mode glutInit(sys.argv) glutInitDisplayMode(GLUT_RGB) glutInitWindowPosition(200,200) glutInitWindowSize(250,250) glutCreateWindow("Des triangles") mode = GL_TRIANGLES glutDisplayFunc(display) glutKeyboardFunc(clavier) glutMainLoop() main()