L'exécutable

TP02-03-01.png TP02-03-02.png TP02-03-03.png

Fichier source : ParametragesGLUt3.cpp
Modules utilitaires

/* Fonction executee lorsqu'aucun evenement     */
/* n'est en file d'attente                      */

static float r0 = 0.0F;
static float r1 = 0.0F;
static float r2 = 0.0F;

static void idle(void) {
  r0 += 0.3355F;
  r1 += 0.6117F;
  r2 += 0.4174F;
  glutPostRedisplay();
}

static int mode = 1;

/* Scene dessinee                               */

static void scene1(void) {
  glPushMatrix();
  glPushMatrix();
  glTranslatef(2.0F,0.0F,2.0F);
  glutSolidCube(2.0);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(2.0F,0.0F,-2.0F);
  glutSolidCube(2.0);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-2.0F,0.0F,2.0F);
  glutSolidCube(2.0);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-2.0F,0.0F,-2.0F);
  glutSolidCube(2.0);
  glPopMatrix();
  glPopMatrix();
}

static void scene2(void) {
  glPushMatrix();
  glPushMatrix();
  glTranslatef(2.0F,0.0F,2.0F);
  glutSolidSphere(1.0,36,18);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(2.0F,0.0F,-2.0F);
  glutSolidSphere(1.0,36,18);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-2.0F,0.0F,2.0F);
  glutSolidSphere(1.0,36,18);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-2.0F,0.0F,-2.0F);
  glutSolidSphere(1.0,36,18);
  glPopMatrix();
  glPopMatrix();
}

/* Fonction executee lors d'un rafraichissement */
/* de la fenetre de dessin                      */

static void display1(void) {
  glClearColor(0.3F,0.3F,0.3F,0.5F);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  const GLfloat light0_position[] = { 0.0,0.0,0.0,1.0 };
  const GLfloat light1_position[] = { -1.0,1.0,1.0,0.0 };
  const GLfloat light2_position[] = { 1.0,-1.0,1.0,0.0 };
  glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
  glLightfv(GL_LIGHT1,GL_POSITION,light1_position);
  glLightfv(GL_LIGHT2,GL_POSITION,light2_position);
  glPolygonMode(GL_FRONT_AND_BACK,( mode ) ? GL_FILL : GL_LINE);
  glPushMatrix();
  glRotatef(r0,1.0,0.0,0.0);
  glRotatef(r1,0.0,1.0,0.0);
  glRotatef(r2,0.0,0.0,1.0);
  scene1();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
  int error = glGetError();
  if ( error != GL_NO_ERROR )
    printf("Attention erreur %d\n",error);
}

static void display2(void) {
  glClearColor(0.3F,0.3F,0.3F,0.5F);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  const GLfloat light0_position[] = { 0.0,0.0,0.0,1.0 };
  const GLfloat light1_position[] = { -1.0,1.0,1.0,0.0 };
  const GLfloat light2_position[] = { 1.0,-1.0,1.0,0.0 };
  glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
  glLightfv(GL_LIGHT1,GL_POSITION,light1_position);
  glLightfv(GL_LIGHT2,GL_POSITION,light2_position);
  glPolygonMode(GL_FRONT_AND_BACK,( mode ) ? GL_FILL : GL_LINE);
  glPushMatrix();
  glRotatef(r0,1.0,0.0,0.0);
  glRotatef(r1,0.0,1.0,0.0);
  glRotatef(r2,0.0,0.0,1.0);
  scene2();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
  int error = glGetError();
  if ( error != GL_NO_ERROR )
    printf("Attention erreur %d\n",error);
}

/* Fonction executee lors de l'appui            */
/* d'une touche alphanumerique du clavier       */

static void keyboard(unsigned char key,int x,int y) {
  switch (key) {
    case 0x0D :
      { static int anim = 0;
        anim = !anim;
        glutIdleFunc(( anim ) ? idle : NULL); }
      break;
    case 0x20 :
      { static int objet = 1;
        objet = !objet;
        glutDisplayFunc(( objet ) ? display1 : display2); }
      glutPostRedisplay();
      break;
    case 'm' :
      { mode = !mode; }
      glutPostRedisplay();
      break;
    case 0x1B :
      exit(0);
      break; }
}

RETOUR