L'exécutable

Le source : TP-Lumieres.cpp

/* Auteur: Nicolas JANEY           */
/* nicolas.janey@univ-fcomte.fr    */
/* Avril 2001                      */
/* Une animation sur les lumieres  */

#include <stdlib.h>

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

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

static float anglex = 0 ;
static float angley = 0 ;
static float anglez = 0 ;
static int anim = 0 ;
static int scene = 0 ;
static int nf = 100 ;

void myinit(void) {
  GLfloat shininess[] = { 50.0 };
  glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc());
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc());
  glMaterialfv(GL_FRONT,GL_AMBIENT,couleurNoir());
  glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurRouge());
  glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBleu());
  glLightfv(GL_LIGHT0,GL_SPECULAR,couleurVert());
  glLightfv(GL_LIGHT1,GL_SPECULAR,couleurVert());
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_LIGHTING);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glPushMatrix() ;
  manipulateurSouris();
  manipulateurClavier();
  glPushMatrix() ;
  glRotatef(anglex,1.0F,0.0F,0.0F) ;
  glRotatef(angley,0.0F,1.0F,0.0F) ;
  glRotatef(anglez,0.0F,0.0F,1.0F) ;
  if ( scene ) {
    glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,180);
    glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,180);
    GLfloat light0_position[] = { 1.0F,0.0F,0.0F,0.0F };
    GLfloat light1_position[] = { -1.0F,0.0F,0.0F,0.0F };
    glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
    glLightfv(GL_LIGHT1,GL_POSITION,light1_position); }
    else {
    glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,20);
    glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,25);
    GLfloat light0_dir[] = { -1.0f,0.0f,0.0f };
    GLfloat light1_dir[] = { 1.0f,0.0f,0.0f };
    glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,light0_dir);
    glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,light1_dir);
    GLfloat light0_position[] = { 2.0f,0.0f,0.0f,1.0f };
    GLfloat light1_position[] = { -2.0f,0.0f,0.0f,1.0f };
    glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
    glLightfv(GL_LIGHT1,GL_POSITION,light1_position); }
  glPopMatrix() ;
  glPushMatrix() ;
  glutSolidSphere(1.0,nf,nf);
  glPopMatrix() ;
  glPopMatrix() ;
  glFlush();
  glutSwapBuffers() ;
}

void idle(void) {
  if ( anim ) {
    anglex++ ;
    angley-- ;
    anglez+=2 ;
    glutPostRedisplay() ; }
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key) {
      case 0x0D : scene = (scene+1) % 2 ;
                  glutPostRedisplay();
                  break ;
      case 45   : nf--;
                  if ( nf < 8 )
                    nf = 8;
                  glutPostRedisplay();
                  break ;
      case 43   : nf++;
                  glutPostRedisplay();
                  break ;
      case ' '  : anim = 1 - anim;
                  glutPostRedisplay();
                  break ;
      case 0x1B : exit(0) ;
                  break; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(300,300); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Lumières mouvantes"); 
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-1.5,1.5,-1.5,1.5,-150.0,150.0);
  glutReshapeFunc(reshapeOrthoBasique);
  glutIdleFunc(idle);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  setManipulateurDistance(1.0F);
  glutKeyboardFunc(key);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR