#include "windows.h" #include #include #include #include #include /* ************************************************** */ static int w = 0 ; static int h = 0 ; static int anim = 0 ; static int image = 0 ; /* ************************************************** */ void CALLBACK myReshape(int ww,int hh) { w = ww ; h = hh ; glViewport(0,0,ww,hh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/60,w/60,-h/120,h/30-h/120,-10.0,10.0); glMatrixMode(GL_MODELVIEW); } /* -------------------------------------------------- */ /* Fonction d'initialisation. */ /* - Une lumiere blanche */ /* - Matiere diffusante rouge */ /* - Activation de l'elimination des parties cachees */ /* -------------------------------------------------- */ void myinit(void) { GLfloat light_ambient[] = { 0.0F,0.0F,0.0F,1.0F }; GLfloat light_diffuse[] = { 1.0F,1.0F,1.0F,1.0F }; GLfloat light_specular[] = { 1.0F,1.0F,1.0F,1.0F }; GLfloat light_position[] = { 1.0F,1.0F,1.0F,0.0F }; glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); GLfloat rouge[] = { 1.0F,0.0F,0.0F,0.0F }; glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,rouge); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); } /* -------------------------------------------------- */ /* Dessin d'une image. */ /* - Effacement de la fenetre. */ /* - Empilement de la transformation courante. */ /* - Translation selon l'axe y de valeur fonction */ /* du numero de l'image. */ /* - Dessin de la sphere. */ /* - Flush de l'image. */ /* - Depilement de la transformation courante. */ /* -------------------------------------------------- */ void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); if ( image < 100 ) glTranslatef(0.0F,10.0F-image*image/1000,0.0F) ; else glTranslatef(0.0F,10.0F-(200-image)*(200-image)/1000,0.0F) ; auxSolidSphere(1.0) ; glPopMatrix(); glFlush(); auxSwapBuffers(); } /* -------------------------------------------------- */ /* Gestion de l'animation. */ /* Si une animation est en cours : */ /* - Le numero de l'image est incremente. */ /* - Si le numero de l'image devient superieur */ /* a 200, il redevient egal a 0 et l'animation */ /* est desactivee. */ /* - Le dessin d'une image est demande. */ /* -------------------------------------------------- */ void CALLBACK idle(void) { if ( anim ) { image++ ; if ( image > 200 ) { image = 0 ; anim = 0 ; } display() ; } } /* -------------------------------------------------- */ /* Activation/Desactivation de l'animation. */ /* -------------------------------------------------- */ void CALLBACK keyA(void) { anim = !anim ; } /* -------------------------------------------------- */ void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH); auxInitPosition(10,10,300,500); auxInitWindow("Exercice 2 : La sphere"); myinit(); auxIdleFunc(idle); auxKeyFunc(AUX_A,keyA); auxReshapeFunc(myReshape); auxMainLoop(display); } /* ************************************************** */