from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * import sys def ecran(): global pv # Le point de vue glClearColor(0,0,0,0) glClear(GL_COLOR_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluLookAt(pv[0],pv[1],pv[2],pv[3],pv[4],pv[5],pv[6],pv[7],pv[8]) glColor3d(1,0,0) glBegin(GL_LINE_LOOP) glVertex3f(0.5,0.5,0.0) glVertex3f(0.,0.,1.0) glVertex3f(0.5,-0.5,0.0) glVertex3f(0.5,0.5,0.0) glVertex3f(-0.5,0.5,0.0) glVertex3f(0.,0.,1.0) glVertex3f(-0.5,-0.5,0.0) glVertex3f(-0.5,0.5,0.0) glVertex3f(0.5,0.5,0.0) glVertex3f(0.5,-0.5,0.0) glVertex3f(-0.5,-0.5,0.0) glVertex3f(-0.5,0.5,0.0) glEnd() glFlush() def clavier(*args): global pv # Le point de vue if args[0] == 'q': sys.exit() elif args[0] == 'a': pv = (-2.,-1.,.0,0.,0.,0.,0.,0.,1.) elif args[0] == 'z': pv = (-2.,-1.,.5,0.,0.,0.,0.,0.,1.) elif args[0] == 'e': pv = (-2.,-1.,1.5,0.,0.,0.,0.,1.,1.) elif args[0] == 'r': pv = (-3.,-1.,.5,0.,0.,0.,0.,0.,1.) glutPostRedisplay() def reshape(*args): glViewport(0,0,args[0],args[1]) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(60.0,float(args[0])/args[1],1.,10.) def main(): global pv # Le point de vue pv = (-2.,-1.,.5,0.,0.,0.,0.,0.,1.) glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA) glutInitWindowPosition(100,100) glutInitWindowSize(320,320) glutCreateWindow("Une pyramide") glutDisplayFunc(ecran) glutKeyboardFunc(clavier) glutReshapeFunc(reshape) glutMainLoop() main()