L'exécutable

Le source: ProblemeGouraud.cpp

/* Auteur: Nicolas JANEY                   */
/* nicolas.janey@univ-fcomte.fr            */
/* Avril 2001                              */
/* Illustration des problemes d'affichage  */
/* lies a l'algorithme de Gouraud          */

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

#include <math.h>

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

static int aff = 0;
static int mode = 0;
static float amp = 0.3F;

void initlights(void) { 
  GLfloat shininess[] = { 0.0F }; 
  glEnable(GL_LIGHTING); 
  glEnable(GL_LIGHT0); 
  glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir()); 
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBrun()); 
  glMaterialfv(GL_FRONT,GL_SPECULAR,couleurNoir()); 
  glMaterialfv(GL_FRONT,GL_SHININESS,shininess); 

  
void scene1(void) { 
  float nx = -2*amp;
  float nz = 1;
  float d = sqrt(nx*nx+nz*nz);
  nx /= d;
  nz /= d;
  glPushMatrix(); 
  glBegin(GL_QUAD_STRIP) ;
  glNormal3f(nx,0.0F,nz) ;
  glVertex3f(-3.0F,2.0F,-amp) ;
  glVertex3f(-3.0F,-2.0F,-amp) ;
  glNormal3f(0.0F,0.0F,1.0F) ;
  glVertex3f(-2.0F,2.0F,amp) ;
  glVertex3f(-2.0F,-2.0F,amp) ;
  glVertex3f(-1.0F,2.0F,-amp) ;
  glVertex3f(-1.0F,-2.0F,-amp) ;
  glVertex3f(0.0F,2.0F,amp) ;
  glVertex3f(0.0F,-2.0F,amp) ;
  glVertex3f(1.0F,2.0F,-amp) ;
  glVertex3f(1.0F,-2.0F,-amp) ;
  glVertex3f(2.0F,2.0F,amp) ;
  glVertex3f(2.0F,-2.0F,amp) ;
  glNormal3f(-nx,0.0F,nz) ;
  glVertex3f(3.0F,2.0F,-amp) ;
  glVertex3f(3.0F,-2.0F,-amp) ;
  glEnd() ;
  if ( aff ) {
    glPushMatrix();
    glTranslatef(-2.5F,0.0F,0.0F);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-1.5F,0.0F,0.0F);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-0.5F,0.0F,0.0F);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(0.5F,0.0F,0.0F);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(1.5F,0.0F,0.0F);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(2.5F,0.0F,0.0F);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-3.0F,2.0F,-amp);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-3.0F,-2.0F,-amp);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(3.0F,2.0F,-amp);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(3.0F,-2.0F,-amp);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    for ( int i = -2 ; i <=2 ; i++ ) {
      glPushMatrix();
      glTranslatef(i,-2.0F,( i%2 == 0 ) ? amp : -amp);
      flecheEnVolume(0.0F,0.0F,1.0,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(i,2.0F,( i%2 == 0 ) ? amp : -amp);
      flecheEnVolume(0.0F,0.0F,1.0,0.1F,0.25F,0.02F);
      glPopMatrix(); } }
  glPopMatrix(); 

  
void scene2(void) { 
  float nx = -2*amp;
  float nz = 1;
  float d = sqrt(nx*nx+nz*nz);
  nx /= d;
  nz /= d;
  glPushMatrix(); 
  glBegin(GL_QUADS) ;
  glNormal3f(nx,0.0F,nz) ;
  glVertex3f(-3.0F,2.0F,-amp) ;
  glVertex3f(-3.0F,-2.0F,-amp) ;
  glVertex3f(-2.0F,-2.0F,amp) ;
  glVertex3f(-2.0F,2.0F,amp) ;
  glNormal3f(-nx,0.0F,nz) ;
  glVertex3f(-2.0F,2.0F,amp) ;
  glVertex3f(-2.0F,-2.0F,amp) ;
  glVertex3f(-1.0F,-2.0F,-amp) ;
  glVertex3f(-1.0F,2.0F,-amp) ;
  glNormal3f(nx,0.0F,nz) ;
  glVertex3f(-1.0F,2.0F,-amp) ;
  glVertex3f(-1.0F,-2.0F,-amp) ;
  glVertex3f(0.0F,-2.0F,amp) ;
  glVertex3f(0.0F,2.0F,amp) ;
  glNormal3f(-nx,0.0F,nz) ;
  glVertex3f(0.0F,2.0F,amp) ;
  glVertex3f(0.0F,-2.0F,amp) ;
  glVertex3f(1.0F,-2.0F,-amp) ;
  glVertex3f(1.0F,2.0F,-amp) ;
  glNormal3f(nx,0.0F,nz) ;
  glVertex3f(1.0F,2.0F,-amp) ;
  glVertex3f(1.0F,-2.0F,-amp) ;
  glVertex3f(2.0F,-2.0F,amp) ;
  glVertex3f(2.0F,2.0F,amp) ;
  glNormal3f(-nx,0.0F,nz) ;
  glVertex3f(2.0F,2.0F,amp) ;
  glVertex3f(2.0F,-2.0F,amp) ;
  glVertex3f(3.0F,-2.0F,-amp) ;
  glVertex3f(3.0F,2.0F,-amp) ;
  glEnd() ;
  if ( aff ) {
    glPushMatrix();
    glTranslatef(-2.5F,0.0F,0.0F);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-1.5F,0.0F,0.0F);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-0.5F,0.0F,0.0F);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(0.5F,0.0F,0.0F);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(1.5F,0.0F,0.0F);
    flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(2.5F,0.0F,0.0F);
    flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
    glPopMatrix();
    int i ;
    for ( i = 0 ; i < 3 ; i++ ) {
      glPushMatrix();
      glTranslatef(-2.0F+2*i,2.0F,amp);
      flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(-2.0F+2*i,-2.0F,amp);
      flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(-3.0F+2*i,2.0F,-amp);
      flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(-3.0F+2*i,-2.0F,-amp);
      flecheEnVolume(nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix(); }
    for ( i = 0 ; i < 3 ; i++ ) {
      glPushMatrix();
      glTranslatef(-1.0F+2*i,2.0F,-amp);
      flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(-1.0F+2*i,-2.0F,-amp);
      flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(-2.0F+2*i,2.0F,amp);
      flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix();
      glPushMatrix();
      glTranslatef(-2.0F+2*i,-2.0F,amp);
      flecheEnVolume(-nx,0.0F,nz,0.1F,0.25F,0.02F);
      glPopMatrix(); } }
  glPopMatrix(); 

  
void display(void) { 
  GLfloat pos[] = { -1.0F,0.0F,1.0F,0.0F }; 
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
  glPushMatrix(); 
  manipulateurSouris();
  manipulateurClavier();
  glLightfv(GL_LIGHT0,GL_POSITION,pos); 
  if ( mode == 0 )
    scene1();
    else
    scene2();
  glPopMatrix(); 
  glFlush();
  glutSwapBuffers();

  
void myinit(void) { 
  glClearColor(0.8F,0.8F,1.0F,1.0F); 
  glEnable(GL_DEPTH_TEST); 
  glEnable(GL_AUTO_NORMAL); 
  glEnable(GL_NORMALIZE); 
  initlights(); 

  
void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 43   : amp += 0.02F;
                  glutPostRedisplay();
                  break;
      case 45   : amp -= 0.02F;
                  glutPostRedisplay();
                  break;
      case 0x0D : aff = (aff+1)%2;
                  glutPostRedisplay();
                  break;
      case ' '  : mode = (mode+1)%2;
                  glutPostRedisplay();
                  break; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(300,200); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Problème avec Gouraud"); 
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-3.2F,3.2F,-3.2F,3.2F,-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

WB01624_.gif (281 octets) RETOUR