/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Illustration du clipping 3D en OpenGL */ #include #include #include #include #include #include #include static float anglex = 0.0F ; static float angley = 0.0F ; static int clip = 0 ; void CALLBACK display(void) { double equ0[] = { 1.1,1.2,0.9,0.8 } ; double equ1[] = { -1.3,1.8,1.5,2.5 } ; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glPushMatrix(); glRotatef(angley,0.0F,1.0F,0.0F) ; glRotatef(anglex,1.0F,0.0F,0.0F) ; glClipPlane(GL_CLIP_PLANE0,equ0); glClipPlane(GL_CLIP_PLANE1,equ1); glPopMatrix(); auxSolidSphere(8.0); glPopMatrix(); glFlush(); auxSwapBuffers(); } void myinit (void) { glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); GLfloat specularFront[] = { 1.0,1.0,1.0,1.0 }; GLfloat shininesFront[] = { 50.0 }; glClearColor(0.5,0.5,1.0,1.0) ; glMaterialfv(GL_FRONT,GL_SPECULAR,specularFront); glMaterialfv(GL_FRONT,GL_SHININESS,shininesFront); GLfloat specularBack[] = { 1.0,1.0,1.0,1.0 }; GLfloat diffuseBack[] = { 1.0,0.0,0.0,1.0 }; GLfloat shininesBack[] = { 50.0 }; glMaterialfv(GL_BACK,GL_SPECULAR,specularBack); glMaterialfv(GL_BACK,GL_SHININESS,shininesBack); glMaterialfv(GL_BACK,GL_DIFFUSE,diffuseBack); GLfloat l_pos0[] = { 1.0,1.0,1.0,0.0 }; glLightfv(GL_LIGHT0,GL_POSITION,l_pos0); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glEnable(GL_CLIP_PLANE0); glEnable(GL_CLIP_PLANE1); } void CALLBACK myReshape(int w, int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10,10,-10/(double) w*h,10/(double) w*h,-10.0,10.0); 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 space(void) { clip = 1 - clip ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition (0,0,300,300); auxInitWindow("Clipping") ; myinit(); auxKeyFunc(AUX_UP,up) ; auxKeyFunc(AUX_DOWN,down) ; auxKeyFunc(AUX_LEFT,left) ; auxKeyFunc(AUX_RIGHT,right) ; auxKeyFunc(AUX_SPACE,space) ; auxReshapeFunc(myReshape); auxMainLoop(display); }