L'exécutable

 Temple1.gif (5936 octets) Temple1.gif (5936 octets)

Temple1.gif (5936 octets)  Temple1.gif (5936 octets)

Le source : TP-Lumieres.cpp

#include "windows.h"

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

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

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 blanc[] = { 1.0f,1.0f,1.0f,1.0f };
static GLfloat noir[] = { 0.0f,0.0f,0.0f,1.0f };

void myinit(void) {
  GLfloat shininess[] = { 50.0 };
  glMaterialfv(GL_FRONT,GL_SPECULAR,blanc);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,blanc);
  glMaterialfv(GL_FRONT,GL_AMBIENT,noir);
  glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,rouge);
  glLightfv(GL_LIGHT1,GL_DIFFUSE,bleu);
  glLightfv(GL_LIGHT0,GL_SPECULAR,vert);
  glLightfv(GL_LIGHT1,GL_SPECULAR,vert);
  glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,20);
  glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,25);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
}

void CALLBACK display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  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 ) {
    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 {
    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);  glEnable(GL_LIGHTING);
    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() ;
  if ( obj )
    glutSolidSphere(1.0,nf,nf);
    else
    auxSolidSphere(1.0);
  glPopMatrix() ;
  glFlush();
  auxSwapBuffers() ;
}

void CALLBACK myReshape(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  if (w <= h) 
    glOrtho (-1.5,1.5,-1.5*(GLfloat)h/(GLfloat)w,1.5*(GLfloat)h/(GLfloat)w,-10.0,10.0);
    else 
    glOrtho (-1.5*(GLfloat)w/(GLfloat)h,1.5*(GLfloat)w/(GLfloat)h,-1.5,1.5,-10.0,10.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

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

void CALLBACK keyReturn(void) {
  obj = 1 - obj;
}

void CALLBACK keySpace(void) {
  anim = 1 - anim;
}

void CALLBACK keyUp(void) {
  nf++;
}

void CALLBACK keyDown(void) {
  nf--;
  if ( nf < 8 )
    nf = 8;
}

void CALLBACK keyA(void) {
  scene = 1 - scene;
}

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH);
  auxInitPosition(0,0,300,300);
  auxInitWindow("Lumières mouvantes");
  myinit();
  auxIdleFunc(idle) ;
  auxKeyFunc(AUX_RETURN,keyReturn) ;
  auxKeyFunc(AUX_SPACE,keySpace) ;
  auxKeyFunc(AUX_A,keyA) ;
  auxKeyFunc(AUX_a,keyA) ;
  auxKeyFunc(AUX_UP,keyUp) ;
  auxKeyFunc(AUX_DOWN,keyDown) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}
WB01624_.gif (281 octets) RETOUR