/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Illustration de l'utilisation */ /* des listes d'affichage en OpenGL */ /* et de l'avantage en rapidite */ /* qu'elles apportent. */ #include #include #include #include #include #include #include #include #define PI 3.14159 static int l = 0 ; void cercle() { GLint i ; GLfloat cosinus,sinus ; glBegin(GL_POLYGON) ; for ( i = 0 ; i < 100 ; i++ ) { cosinus =(float) cos(i*2*PI/100.0); sinus =(float) sin(i*2*PI/100.0); glVertex2f(cosinus,sinus) ; } glEnd() ; } void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0F,0.0F,0.0F); struct timeb t1 ; struct timeb t2 ; ftime(&t1); for ( int k = 0 ; k < 3000 ; k++ ) for ( int j = 0 ; j < 3 ; j++ ) for ( int i = 0 ; i < 3 ; i++ ) { glPushMatrix(); glTranslatef(-3.0F+3*i,-3.0F+3*j,(float) -k) ; if ( l ) cercle(); else glCallList(1) ; glPopMatrix(); } ftime(&t2); int milli = ((int) t2.time - (int) t1.time)*1000 + (int) t2.millitm - (int) t1.millitm ; printf("%d millisecondes\n",milli) ; glFlush(); auxSwapBuffers(); } void cercleListe() { GLint i ; GLfloat cosinus,sinus ; glNewList(1,GL_COMPILE) ; glBegin(GL_POLYGON) ; for ( i = 0 ; i < 100 ; i++ ) { cosinus =(float) cos(i*2*PI/100.0); sinus =(float) sin(i*2*PI/100.0); glVertex2f(cosinus,sinus) ; } glEnd() ; glEndList() ; } void myinit(void) { glClearColor(1.0,1.0,1.0,1.0); cercleListe() ; } void CALLBACK myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(85.,(float)w/(float)h,1.0,20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0,0.0,-5.0); } void CALLBACK keyL(void) { l++; l %= 2; } void CALLBACK keyl(void) { l++; l %= 2; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGB); auxInitPosition(0,0,200,200); auxInitWindow("Liste d'affichage"); myinit(); auxKeyFunc(AUX_L,keyL); auxKeyFunc(AUX_l,keyl); auxReshapeFunc(myReshape); auxMainLoop(display); }