/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Les primitives graphiques OpenGL */ #include #include #include #include #include #include static float anglex = 0.0F ; static float angley = 0.0F ; static int obj = 0 ; void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(0.0F,0.0F,0.0F); glPushMatrix(); glRotatef(angley,0.0F,1.0F,0.0F) ; glRotatef(anglex,1.0F,0.0F,0.0F) ; switch ( obj ) { case 0 : glBegin(GL_POINTS) ; glVertex3f(-7.0F,4.0F,1.0F) ; glVertex3f(8.0F,-1.0F,-2.0F) ; glVertex3f(-3.0F,7.0F,3.0F) ; glVertex3f(-1.0F,-8.0F,0.0F) ; glVertex3f(2.0F,-4.0F,5.0F) ; glVertex3f(5.0F,8.0F,1.0F) ; glEnd() ; break ; case 1 : glBegin(GL_LINES) ; glVertex3f(-7.0F,4.0F,-1.0F) ; glVertex3f(8.0F,-1.0F,2.0F) ; glVertex3f(-3.0F,7.0F,0.0F) ; glVertex3f(-1.0F,-8.0F,4.0F) ; glVertex3f(2.0F,-4.0F,-2.0F) ; glVertex3f(5.0F,8.0F,3.0F) ; glEnd() ; break ; case 2 : glBegin(GL_LINE_STRIP) ; glVertex3f(-7.0F,4.0F,-1.0F) ; glVertex3f(8.0F,-1.0F,2.0F) ; glVertex3f(-3.0F,7.0F,0.0F) ; glVertex3f(-1.0F,-8.0F,4.0F) ; glVertex3f(2.0F,-4.0F,-2.0F) ; glVertex3f(5.0F,8.0F,3.0F) ; glEnd() ; break ; case 3 : glBegin(GL_LINE_LOOP) ; glVertex3f(-7.0F,4.0F,-1.0F) ; glVertex3f(8.0F,-1.0F,2.0F) ; glVertex3f(-3.0F,7.0F,0.0F) ; glVertex3f(-1.0F,-8.0F,4.0F) ; glVertex3f(2.0F,-4.0F,-2.0F) ; glVertex3f(5.0F,8.0F,3.0F) ; glEnd() ; break ; case 4 : glBegin(GL_POLYGON) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex3f(-7.0F,4.0F,0.0F) ; glVertex3f(-3.0F,7.0F,0.0F) ; glVertex3f(5.0F,8.0F,0.0F) ; glVertex3f(8.0F,-1.0F,0.0F) ; glVertex3f(2.0F,-4.0F,0.0F) ; glVertex3f(-1.0F,-8.0F,0.0F) ; glEnd() ; break ; case 5 : glBegin(GL_QUADS) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex3f(-7.0F,2.0F,1.0F) ; glVertex3f(-1.0F,7.0F,1.0F) ; glVertex3f(2.0F,6.0F,1.0F) ; glVertex3f(-6.0F,-3.0F,1.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(3.0F,-8.0F,-2.0F) ; glVertex3f(7.0F,-5.0F,-2.0F) ; glVertex3f(9.0F,2.0F,-2.0F) ; glVertex3f(1.0F,-3.0F,-2.0F) ; glEnd() ; break ; case 6 : glBegin(GL_QUAD_STRIP) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex3f(-7.0F,5.0F,0.0F) ; glVertex3f(-3.0F,8.0F,0.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(-4.0F,-2.0F,0.0F) ; glVertex3f(0.0F,3.0F,0.0F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex3f(2.0F,-2.5F,0.0F) ; glVertex3f(3.0F,5.0F,0.0F) ; glColor3f(0.0F,1.0F,1.0F) ; glVertex3f(8.5F,0.0F,0.0F) ; glVertex3f(8.0F,2.0F,0.0F) ; glEnd() ; break ; case 7 : glBegin(GL_TRIANGLES) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex3f(-7.0F,-6.0F,2.0F) ; glVertex3f(-5.0F,7.0F,-4.0F) ; glVertex3f(2.0F,-5.0F,-1.0F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex3f(-3.0F,8.0F,-5.0F) ; glVertex3f(7.0F,-5.0F,3.0F) ; glVertex3f(9.0F,7.0F,2.0F) ; glEnd() ; break ; case 8 : glBegin(GL_TRIANGLE_STRIP) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex3f(-7.0F,5.0F,3.0F) ; glVertex3f(-3.0F,8.0F,2.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(-4.0F,-2.0F,-1.0F) ; glVertex3f(0.0F,3.0F,0.0F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex3f(2.0F,-2.5F,5.0F) ; glVertex3f(3.0F,5.0F,3.0F) ; glColor3f(0.0F,1.0F,1.0F) ; glVertex3f(8.5F,0.0F,-1.0F) ; glVertex3f(8.0F,2.0F,-2.0F) ; glEnd() ; break ; case 9 : glBegin(GL_TRIANGLE_FAN) ; glColor3f(0.0F,0.0F,1.0F) ; glVertex3f(0.0F,7.0F,3.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(-7.0F,-2.0F,2.0F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex3f(-4.0F,-6.0F,-1.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(-1.0F,-8.0F,0.0F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex3f(1.0F,-1.0F,5.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(3.0F,-4.0F,3.0F) ; glColor3f(0.0F,1.0F,0.0F) ; glVertex3f(6.0F,1.0F,-1.0F) ; glColor3f(1.0F,0.0F,0.0F) ; glVertex3f(8.0F,5.0F,-2.0F) ; glEnd() ; } glPopMatrix(); glFlush(); auxSwapBuffers(); } void myinit (void) { glClearColor(1.0,1.0,1.0,1.0); glEnable(GL_DEPTH_TEST) ; } void CALLBACK myReshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10.0,10.0,-10.0/w*h,10.0/w*h,-20.0,20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity (); } void CALLBACK up(void) { anglex-- ; } void CALLBACK down(void) { anglex++ ; } void CALLBACK left(void) { angley-- ; } void CALLBACK right(void) { angley++ ; } void CALLBACK space(void) { obj++ ; if ( obj == 10 ) obj = 0 ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition(0,0,200,200); auxInitWindow("Primitives graphiques"); myinit(); auxKeyFunc(AUX_UP,up) ; auxKeyFunc(AUX_DOWN,down) ; auxKeyFunc(AUX_LEFT,left) ; auxKeyFunc(AUX_RIGHT,right) ; auxKeyFunc(AUX_SPACE,space) ; auxReshapeFunc (myReshape); auxMainLoop(display); }