#include #include "travail.h" void tracerScene(Objet *obj) { static float g = 0; glEnable(GL_STENCIL_TEST); glClear(GL_STENCIL_BUFFER_BIT); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Activation du stencil glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); obj->gonfler(0.8); obj->tracer(); obj->gonfler(-0.8); // Trace le petit objet à l'intéreiur glDepthFunc(GL_ALWAYS); glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); obj->gonfler(0.2); obj->tracer(); obj->gonfler(-0.2); // Reactivation du Z & clear glDepthFunc(GL_LESS); glClear(GL_DEPTH_BUFFER_BIT); // Reactivation des couleurs glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // Tracage qu'à l'endroit nécessaire glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilFunc(GL_EQUAL, 1, 1); // Tracer l'entourage glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -1, 1); glDisable(GL_LIGHTING); glColor3f(0, 1, 0); glBegin(GL_POLYGON); glVertex3f(-1, -1, 0); glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glVertex3f(-1, 1, 0); glEnd(); glEnable(GL_LIGHTING); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); // Revenir a un tracé normal glStencilFunc(GL_ALWAYS, 1, 1); // Dessin de l'objet glColor3f(1,0,0); obj->tracer(); g += 0.01; // Dessin des boules glColor3f(0,0,1); for(int j=0;j<5;j++) { for(int i=0;i<5;i++) { glPushMatrix(); glTranslatef(5.0*(i-2),5.0*(j-2),-20); glutSolidSphere(1,10,10); glPopMatrix(); } } }