L'exécutable

Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets)

Toutes les lumières allumées

Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets)

Contribution individuelle de la lumière ponctuelle centrale

Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets) Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets) Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets)

Contributions individuelles des trois lumières directionnelles

Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets) Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets) Exam-TD2-2004-2005-Exo4-01.jpg (18577 octets)

Même scène avec l'intensité des lumières réduite de 75%

Le source : Exam-TD2-2004-2005-Exo4.cpp

/* Auteur: Nicolas JANEY               */
/* nicolas.janey@univ-fcomte.fr        */
/* Decembre 2004                       */
/* Un tetraedre de spheres             */

#include <stdio.h>
#include <stdlib.h>

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

#include "ModuleMenus.h"
#include "ModuleManipulateur.h"

static int mode = 0;
static  GLfloat noir[] = { 0.0F,0.0F,0.0F,1.0F };
static  GLfloat rouge[] = { 1.0F,0.0F,0.0F,1.0F };
static  GLfloat vert[] = { 0.0F,1.0F,0.0F,1.0F };
static  GLfloat bleu[] = { 0.0F,0.0F,1.0F,1.0F };
static  GLfloat jaune[] = { 1.0F,1.0F,0.0F,1.0F };
static  GLfloat cyan[] = { 0.0F,1.0F,1.0F,1.0F };
static  GLfloat magenta[] = { 1.0F,0.0F,1.0F,1.0F };
static  GLfloat blanc[] = { 1.0F,1.0F,1.0F,1.0F };
static  GLfloat gris[] = { 0.25F,0.25F,0.25F,1.0F };

void myinit(void) {
  glClearColor(0.75F,0.75F,0.75F,1.0F) ;
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_AUTO_NORMAL);
  glEnable(GL_NORMALIZE);
}

void lumieres(void) {
  switch ( mode ) {
    case 0 : glLightfv(GL_LIGHT0,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT0,GL_SPECULAR,blanc);
             glLightfv(GL_LIGHT1,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT1,GL_SPECULAR,blanc);
             glLightfv(GL_LIGHT2,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT2,GL_SPECULAR,blanc);
             glLightfv(GL_LIGHT3,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT3,GL_SPECULAR,blanc);
             break;
    case 1 : glLightfv(GL_LIGHT0,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT0,GL_SPECULAR,blanc);
             glLightfv(GL_LIGHT1,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT1,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT2,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT2,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT3,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT3,GL_SPECULAR,noir);
             break;
    case 2 : glLightfv(GL_LIGHT0,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT0,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT1,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT1,GL_SPECULAR,blanc);
             glLightfv(GL_LIGHT2,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT2,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT3,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT3,GL_SPECULAR,noir);
             break;
    case 3 : glLightfv(GL_LIGHT0,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT0,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT1,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT1,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT2,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT2,GL_SPECULAR,blanc);
             glLightfv(GL_LIGHT3,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT3,GL_SPECULAR,noir);
             break;
    case 4 : glLightfv(GL_LIGHT0,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT0,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT1,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT1,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT2,GL_DIFFUSE,noir);
             glLightfv(GL_LIGHT2,GL_SPECULAR,noir);
             glLightfv(GL_LIGHT3,GL_DIFFUSE,blanc);
             glLightfv(GL_LIGHT3,GL_SPECULAR,blanc);
             break;
    case 5 : glLightfv(GL_LIGHT0,GL_DIFFUSE,gris);
             glLightfv(GL_LIGHT0,GL_SPECULAR,gris);
             glLightfv(GL_LIGHT1,GL_DIFFUSE,gris);
             glLightfv(GL_LIGHT1,GL_SPECULAR,gris);
             glLightfv(GL_LIGHT2,GL_DIFFUSE,gris);
             glLightfv(GL_LIGHT2,GL_SPECULAR,gris);
             glLightfv(GL_LIGHT3,GL_DIFFUSE,gris);
             glLightfv(GL_LIGHT3,GL_SPECULAR,gris);
             break; }
  GLfloat pos0[] = { 0.0F,0.0F,0.0F,1.0F };
  GLfloat pos1[] = { -1.0F,0.0F,1.0F,0.0F };
  GLfloat pos2[] = { 0.0F,-1.0F,1.0F,0.0F };
  GLfloat pos3[] = { 0.0F,0.0F,1.0F,0.0F };
  glLightfv(GL_LIGHT0,GL_POSITION,pos0);
  glLightfv(GL_LIGHT1,GL_POSITION,pos1);
  glLightfv(GL_LIGHT2,GL_POSITION,pos2);
  glLightfv(GL_LIGHT3,GL_POSITION,pos3);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_LIGHT2);
  glEnable(GL_LIGHT3);
}

void scene(void) {
  lumieres();
  glMaterialf(GL_FRONT,GL_SHININESS,100.0F);
  glPushMatrix();
  glTranslatef(-5.0F,-2.88675F,2.04125F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,rouge);
  glMaterialfv(GL_FRONT,GL_SPECULAR,blanc);
  glutSolidSphere(4.0F,120,120);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(5.0F,-2.88675F,2.04125F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,vert);
  glMaterialfv(GL_FRONT,GL_SPECULAR,noir);
  glutSolidSphere(4.0F,120,120);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,5.7735F,2.04125F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu);
  glMaterialfv(GL_FRONT,GL_SPECULAR,magenta);
  glutSolidSphere(4.0F,120,120);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.0F,-6.12375F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,cyan);
  glMaterialfv(GL_FRONT,GL_SPECULAR,jaune);
  glutSolidSphere(4.0F,120,120);
  glPopMatrix();
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  manipulateurSouris();
  manipulateurClavier();
  scene();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void reshape(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(40.0,(float)w/(float)h,15.0F,45.0F);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(0.0,0.0,30.0,
            0.0,0.0,0.0,
            0.0,1.0,0.0);
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 0x1B   : exit(0);
                    break;
      case ' '    : mode = (mode+1)%6;
                    glutPostRedisplay(); }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(220,220); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Tétraèdre de sphères"); 
  myinit(); 
  creationMenuBasique();
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutIdleFunc(idleBasique);
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR