/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Decembre 2001 */ /* Une sphere illuminee */ #include #include #include #include "ModuleMenus.h" #include "ModuleReshape.h" #include "ModuleManipulateur.h" #include "ModuleCouleurs.h" static int aff = 0; static int mode = 0; static int disc1 = 10; static int disc2 = 10; void myinit(void) { GLfloat shinines[] = { 50.0F }; GLfloat l_pos[] = { 1.0F,1.0F,1.0F,0.0F }; glClearColor(0.5F,0.5F,0.8F,1.0F) ; glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc()); glMaterialfv(GL_FRONT,GL_SPECULAR,couleurGrisFonce()); glMaterialfv(GL_FRONT,GL_SHININESS,shinines); glLightfv(GL_LIGHT0,GL_POSITION,l_pos); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if ( mode ) glShadeModel(GL_SMOOTH); else glShadeModel(GL_FLAT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); if ( aff ) glutWireSphere(1.3,disc1,disc2); else glutSolidSphere(1.3,disc1,disc2); glPopMatrix(); glFlush(); glutSwapBuffers(); } void key(unsigned char key,int x,int y) { if ( keyManipulateur(key,x,y) ) glutPostRedisplay(); else switch ( key ) { case 'a' : disc1++ ; glutPostRedisplay() ; break ; case 'A' : disc1-- ; if ( disc1 < 3 ) disc1 = 3; glutPostRedisplay() ; break ; case 'b' : disc2++ ; glutPostRedisplay() ; break ; case 'B' : disc2-- ; if ( disc2 < 2 ) disc2 = 2; glutPostRedisplay() ; break ; case ' ' : aff = (aff+1)%2 ; glutPostRedisplay() ; break ; case 0x0D : mode = (mode+1)%2 ; glutPostRedisplay() ; break ; } } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(250,250); glutInitWindowPosition(50,50); glutCreateWindow("Simple sphere"); myinit(); creationMenuBasique(); setParametresOrthoBasique(-1.5,1.5,-1.5,1.5,-500.0,500.0); setManipulateurDistance(1.0F); glutReshapeFunc(reshapeOrthoBasique); glutKeyboardFunc(key); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutMainLoop(); return(0); }