/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Illustration du clipping 3D en OpenGL */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
static int clip = 0 ;
void 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();
manipulateurSouris();
manipulateurClavier();
glClipPlane(GL_CLIP_PLANE0,equ0);
glClipPlane(GL_CLIP_PLANE1,equ1);
if ( (clip & 0x01) != 0 )
glEnable(GL_CLIP_PLANE0);
else
glDisable(GL_CLIP_PLANE0);
if ( (clip & 0x02) != 0 )
glEnable(GL_CLIP_PLANE1);
else
glDisable(GL_CLIP_PLANE1);
glPopMatrix();
glutSolidSphere(8.0,30,30);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myinit (void) {
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
GLfloat shininesFront[] = { 50.0 };
glClearColor(0.5,0.5,1.0,1.0) ;
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc());
glMaterialfv(GL_FRONT,GL_SHININESS,shininesFront);
GLfloat shininesBack[] = { 50.0 };
glMaterialfv(GL_BACK,GL_SPECULAR,couleurBlanc());
glMaterialfv(GL_BACK,GL_SHININESS,shininesBack);
glMaterialfv(GL_BACK,GL_DIFFUSE,couleurRouge());
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);
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 32 : clip = (clip+1) %4;
glutPostRedisplay();
break; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,300);
glutInitWindowPosition(50,50);
glutCreateWindow("Clipping");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}