L'exécutable

Le source : ExamTD120052006Exo4.cpp

/* Auteur: Nicolas JANEY            */
/* nicolas.janey@univ-fcomte.fr     */
/* Novembre 2005                    */
/* Animation de lumieres en OpenGL  */

#include <stdio.h>
#include <math.h>

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

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

static float a = 0;
static int f1;
static int fv;

void myinit(void) {
  static float blanc[] = { 1.0F,1.0F,1.0F,1.0F };
  glClearColor(0.75F,0.75F,0.75F,1.0F);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,blanc);
  glLightfv(GL_LIGHT0,GL_SPECULAR,blanc);
  glEnable(GL_LIGHTING);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  static float gris[] = { 0.9F,0.9F,0.9F,1.0F };
  glMaterialfv(GL_FRONT,GL_DIFFUSE,gris);
  glMaterialfv(GL_FRONT,GL_SPECULAR,gris);
  glMaterialf(GL_FRONT,GL_SHININESS,120);
}

void scene(void) {
  glPushMatrix();
  for ( int i = 0 ; i < 10 ; i++ ) {
    glPushMatrix();
    glRotatef(i*36,0.0F,0.0F,1.0F);
    glTranslatef(10.0F,0.0F,0.0F);
    glutSolidSphere(3,180,180);
    glPopMatrix(); }
  glPopMatrix();
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  /* ****** */
  manipulateurSouris();
  manipulateurClavier();
  glDisable(GL_LIGHTING);
  axes();
  glPushMatrix();
  glTranslatef(5.0F,0.0F,0.0F);
  glColor3fv(couleurBlanc());
  glutSolidSphere(0.3,30,30);
  glRotatef(a,0.0F,0.0F,1.0F);
  float x = 30.0F*cos(30.0F*3.14159F/180.0F);
  float y = 30.0F*sin(30.0F*3.14159F/180.0F);
  glBegin(GL_LINES);
  glVertex3f(0.0F,0.0F,0.0F);
  glVertex3f(x,y,0.0F);
  glVertex3f(0.0F,0.0F,0.0F);
  glVertex3f(x,-y,0.0F);
  glEnd();
  glPopMatrix();
  glEnable(GL_LIGHTING);
  /* ****** */
  glPushMatrix();
  glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,30.0F);
  GLfloat lDir[] = { 1.0F,0.0F,0.0F };
  GLfloat lPos[] = { 5.0F,0.0F,0.0F,1.0F };
  glLightfv(GL_LIGHT0,GL_POSITION,lPos);
  glRotatef(a,0.0F,0.0F,1.0F);
  glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,lDir);
  glPopMatrix();
  glPushMatrix();
  scene();
  glPopMatrix();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
  glutPostWindowRedisplay(fv);
}

void idle(void) {
  a += 2.0F;
  if ( a > 360.0F )
    a = 0.0F;
  glutPostWindowRedisplay(f1);
}

void reshapeV(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0,w,-h,0,-1.0,1.0); 
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void displayV() {
  glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
  glClearColor(0.0F,0.0F,0.0F,1.0F);
  glPushMatrix();
  glColor4fv(couleurBlanc());
  float pos = 1.0F;
  placeFontCursor(5.0F,-pos*20.0F,0.0F);
  simpleBitmapOutput(1,REGULAR8x13,"ANGLE    : %6.3f",a);
  glPopMatrix();
  glutSwapBuffers();
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostWindowRedisplay(f1);
    else
    switch ( key ) {
      case ' '  : { static int anim = 1;
                    anim = !anim;
                    glutIdleFunc(( anim ) ? idle : NULL); }
                  break; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  { glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
    glutInitWindowSize(300,300); 
    glutInitWindowPosition(50,50); 
    f1 = glutCreateWindow("Une lumière animée"); 
    myinit(); 
    creationMenuBasique();
    setParametresOrthoBasique(-15.0,15.0,-15.0,15.0,-500.0,500.0);
    setManipulateurDistance(1.0F);
    glutReshapeFunc(reshapeOrthoBasique);
    glutKeyboardFunc(key);
    glutDisplayFunc(display);
    glutMotionFunc(motionBasique);
    glutMouseFunc(sourisBasique); }
  { glutInitWindowSize(300,30);
    glutInitWindowPosition(50,380);
    glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
    fv = glutCreateWindow("Valeurs");
    creationMenuBasique();
    glutDisplayFunc(displayV);
    glutReshapeFunc(reshapeV);
    glutKeyboardFunc(key); }
  glutIdleFunc(idle);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR