/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Illustration de l'utilisation */
/* des listes d'affichage en OpenGL */
/* et de l'avantage en rapidite */
/* qu'elles apportent. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/timeb.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#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 display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor4fv(couleurNoir());
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();
glutSwapBuffers();
}
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 key(unsigned char key,int x,int y) {
switch ( key ) {
case 'L' :
case 'l' : l++;
l %= 2;
glutPostRedisplay();
break;
case '#' : { static int fullScreen = 0;
static int tx;
static int ty;
static int px;
static int py;
fullScreen = !fullScreen;
if ( fullScreen ) {
px = glutGet(GLUT_WINDOW_X);
py = glutGet(GLUT_WINDOW_Y);
tx = glutGet(GLUT_WINDOW_WIDTH);
ty = glutGet(GLUT_WINDOW_HEIGHT);
glutFullScreen(); }
else {
glutPositionWindow(px,py);
glutReshapeWindow(tx,ty); } }
break;
case 0x1B : exit(0);
break; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
glutInitWindowSize(200,200);
glutInitWindowPosition(50,50);
glutCreateWindow("Liste d'affichage");
myinit();
creationMenuBasique();
setParametresPerspectiveBasique(85.0F,1.0F,1.0F,20.0F,0.0F,0.0F,-5.0F);
glutReshapeFunc(reshapePerspectiveBasique);
setParametresPerspectiveBasique(85.0F,1.0F,1.0F,20.0F,0.0F,0.0F,-5.0F);
glutReshapeFunc(reshapePerspectiveBasique);
glutKeyboardFunc(key);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}