L'exécutable

Le source : TP-MaterielLumieres.cpp

/* Auteur: Nicolas JANEY                   */
/* nicolas.janey@univ-fcomte.fr            */
/* Octobre 2004                            */
/* Materiel et lumieres sur des spheres    */

#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>

#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleManipulateur.h"
#include "ModuleCouleurs.h"

static int mode = 0;
static int disc = 120;

void myinit(void) {
  glClearColor(0.0F,0.0F,0.0F,1.0F) ;
  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);
  glPushMatrix();
  manipulateurSouris();
  manipulateurClavier();
  switch ( mode ) {
    case 0 :
    case 1 :
    case 2 : 
    case 5 : glDisable(GL_LIGHT1);
             glDisable(GL_LIGHT2);
             break;
    case 3 : glEnable(GL_LIGHT1);
             glDisable(GL_LIGHT2);
             break;
    case 4 : glEnable(GL_LIGHT1);
             glEnable(GL_LIGHT2);
             break; }
  switch ( mode ) {
    case 0 :
    case 1 : { GLfloat l_pos[] = { 0.0F,0.0F,1.0F,0.0F };
               glLightfv(GL_LIGHT0,GL_POSITION,l_pos);
               glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
               glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
               glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir()); }
             break;
    case 2 :
    case 3 :
    case 4 : { GLfloat l_pos[] = { 1.0F,0.0F,0.0F,0.0F };
               glLightfv(GL_LIGHT0,GL_POSITION,l_pos);
               glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
               glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
               glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir()); }
             { GLfloat l_pos[] = { 0.0F,0.0F,0.0F,1.0F };
               glLightfv(GL_LIGHT1,GL_POSITION,l_pos);
               glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc());
               glLightfv(GL_LIGHT1,GL_SPECULAR,couleurBlanc());
               glLightfv(GL_LIGHT1,GL_AMBIENT,couleurNoir()); }
             { GLfloat l_pos[] = { 0.0F,0.0F,10.0F,1.0F };
               GLfloat l_dir[] = { 0.0F,0.0F,-1.0F,0.0F };
               glLightfv(GL_LIGHT2,GL_POSITION,l_pos);
               glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurBlanc());
               glLightfv(GL_LIGHT2,GL_SPECULAR,couleurBlanc());
               glLightfv(GL_LIGHT2,GL_AMBIENT,couleurNoir());
               glLightfv(GL_LIGHT2,GL_SPOT_DIRECTION,l_dir);
               glLightf(GL_LIGHT2,GL_SPOT_CUTOFF,25); }
             break; }
  switch (mode) {
    case 0 : glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge());
             glMaterialfv(GL_FRONT,GL_SPECULAR,couleurNoir());
             glMaterialfv(GL_FRONT,GL_AMBIENT,couleurNoir());
             glMaterialf(GL_FRONT,GL_SHININESS,20.0F);
             glutSolidSphere(5.0,disc,disc);
             break;
    case 3 : 
    case 4 : glPushMatrix();
             glTranslatef(10.0F,0.0F,0.0F);
             glutSolidSphere(2.0,disc,disc);
             glPopMatrix();
    case 1 :
    case 2 : glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge());
             glMaterialfv(GL_FRONT,GL_SPECULAR,couleurVert());
             glMaterialfv(GL_FRONT,GL_AMBIENT,couleurNoir());
             glMaterialf(GL_FRONT,GL_SHININESS,50.0F);
             glutSolidSphere(5.0,disc,disc);
             break;
    case 5 : GLfloat l_pos[] = { 0.0F,0.0F,0.0F,1.0F };
             glTranslatef(3.0F,0.0F,0.0F);
             glScalef(1.5F,1.5F,1.5F);
             glLightfv(GL_LIGHT0,GL_POSITION,l_pos);
             glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
             glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc());
             glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc());
             glMaterialfv(GL_FRONT,GL_AMBIENT,couleurNoir());
             glMaterialf(GL_FRONT,GL_SHININESS,50.0F);
             glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBleu());
             glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBleu());
             glPushMatrix();
             glTranslatef(5.0F,0.0F,0.0F);
             glutSolidSphere(2.0,disc,disc);
             glPopMatrix();
             glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurVert());
             glLightfv(GL_LIGHT0,GL_SPECULAR,couleurVert());
             glPushMatrix();
             glTranslatef(-5.0F,0.0F,0.0F);
             glutSolidSphere(2.0,disc,disc);
             glPopMatrix();
             break; }
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 43   : disc++ ;
                  glutPostRedisplay() ;
                  break ;
      case 45   : disc-- ;
                  if ( disc < 3 )
                    disc = 3;
                  glutPostRedisplay() ;
                  break ;
      case 0x0D : mode = (mode+1)%6 ;
                  glutPostRedisplay() ;
                  break ; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(240,160); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Materiel et lumieres");
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-5.0,9.0,-7.0,7.0,-50.0,50.0);
  setManipulateurDistance(1.0F);
  glutReshapeFunc(reshapeOrthoBasique);
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR