/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Une sphere blanche illuminee */ /* par des spots colores en OpenGL */ #include #include #include #include #include #include static float anglex = 0.0F ; static float angley = 0.0F ; static GLfloat shininess = 100.0F ; static int nf = 128 ; static float o0 = 10.0F ; static float o1 = 10.0F ; void myinit(void) { GLfloat rouge[] = { 1.0F,0.0F,0.0F,1.0F }; GLfloat specular[] = { 0.0F,0.0F,0.0F,1.0F }; GLfloat bleu[] = { 0.0F,0.0F,1.0F,1.0F }; GLfloat vert[] = { 0.0F,1.0F,0.0F,1.0F }; GLfloat l_pos0[] = { 1.0F,0.0F,2.0F,1.0F }; GLfloat l_dir0[] = { -1.0F,0.0F,-2.0F,1.0F }; GLfloat l_pos1[] = { -1.0F,0.0F,2.0F,1.0F }; GLfloat l_dir1[] = { 1.0F,0.0F,-2.0F,1.0F }; glClearColor(0.5F,0.5F,1.0F,1.0F) ; glMaterialfv(GL_FRONT,GL_SPECULAR,specular); glLightfv(GL_LIGHT0,GL_DIFFUSE,rouge); glLightfv(GL_LIGHT0,GL_POSITION,l_pos0); glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,l_dir0); glLightfv(GL_LIGHT1,GL_DIFFUSE,vert); glLightfv(GL_LIGHT1,GL_POSITION,l_pos1); glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,l_dir1); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); } void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,o0); glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,o1); glRotatef(angley,0.0F,1.0F,0.0F) ; glRotatef(anglex,1.0F,0.0F,0.0F) ; glMaterialf(GL_FRONT,GL_SHININESS,shininess); glutSolidSphere(1.0,nf,nf); printf("Nombre de facettes %d\n",nf*nf) ; glPopMatrix(); glFlush(); auxSwapBuffers(); } void CALLBACK myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(-1.5,1.5,-1.5*(float)h/(float)w,1.5*(float)h/(float)w,-10.,10.); else glOrtho(-1.5*(float)w/(float)h,1.5*(float)w/(float)h,-1.5,1.5,-10.,10.); 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 keys(void) { shininess *= 1.03F ; } void CALLBACK keyS(void) { shininess /= 1.03F ; } void CALLBACK key1(void) { o1 *= 1.1F ; } void CALLBACK key7(void) { o1 /= 1.1F ; } void CALLBACK key2(void) { o0 *= 1.1F ; } void CALLBACK key8(void) { o0 /= 1.1F ; } void CALLBACK keyt(void) { nf *= 2 ; } void CALLBACK keyT(void) { nf /= 2 ; if ( nf == 2 ) nf = 4 ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH); auxInitPosition(0,0,250,250); auxInitWindow("2 spots lumineux"); myinit(); auxKeyFunc(AUX_UP,up) ; auxKeyFunc(AUX_DOWN,down) ; auxKeyFunc(AUX_LEFT,left) ; auxKeyFunc(AUX_RIGHT,right) ; auxKeyFunc(AUX_s,keys) ; auxKeyFunc(AUX_S,keyS) ; auxKeyFunc(AUX_t,keyt) ; auxKeyFunc(AUX_T,keyT) ; auxKeyFunc(AUX_1,key1) ; auxKeyFunc(AUX_7,key7) ; auxKeyFunc(AUX_2,key2) ; auxKeyFunc(AUX_8,key8) ; auxReshapeFunc(myReshape); auxMainLoop(display); }