L'exécutable

Le source: FlatEtSmooth.cpp

#include <windows.h>

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

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

static int mode = 0 ;

void CALLBACK display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  if ( mode )
    glShadeModel(GL_SMOOTH);
    else
    glShadeModel(GL_FLAT);
  glPushMatrix() ;
  glTranslatef(-0.8F,0.0F,0.0F);
  glRotatef(50.0F,1.0F,1.0F,1.0F);
  auxSolidSphere(1.1) ;
  glPopMatrix() ;
  glPushMatrix() ;
  glTranslatef(0.9F,-1.0F,0.0F);
  glRotatef(-70.0F,1.0F,0.0F,0.0F);
  auxSolidCone(0.9,2.0) ;
  glPopMatrix() ;
  glPushMatrix() ;
  glTranslatef(0.8F,0.1F,0.0F);
  glRotatef(-70.0F,1.0F,0.0F,0.0F);
  auxSolidTorus(0.35,0.8) ;
  glPopMatrix() ;
  glFlush();
  auxSwapBuffers();
}

void myinit (void) {
  glClearColor(1.0,1.0,1.0,1.0);
  glEnable(GL_DEPTH_TEST) ;
  glEnable(GL_LIGHTING) ;
  glEnable(GL_LIGHT0) ;
  float dir[] = {0.1F,0.8F,1.6F,0.0F} ;
  glLightfv(GL_LIGHT0,GL_POSITION,dir) ;
}

void CALLBACK myReshape(int w, int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-2.0,2.0,-2.0/w*h,2.0/w*h,-2.0,2.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void CALLBACK auxSpace(void) {
  mode = 1 - mode ;
}

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH);
  auxInitPosition(0,0,500,500);
  auxInitWindow("Affichages flat et smooth") ;
  myinit();
  auxKeyFunc(AUX_SPACE,auxSpace) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}
 RETOUR