L'exécutable

Image060.gif (2376 octets)  Image061.gif (2864 octets)

Image062.gif (3009 octets)  Image063.gif (3075 octets)

Image064.gif (2888 octets)  Image065.gif (2976 octets)

Image066.gif (6659 octets)  Image067.gif (3219 octets)

Image068.gif (6765 octets)  Image069.gif (11650 octets)

Le source: Primitives.cpp

/* Auteur: Nicolas JANEY             */
/* nicolas.janey@univ-fcomte.fr      */
/* Avril 2001                        */
/* Les primitives graphiques OpenGL  */

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

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

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

static int obj = 0 ;

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glColor4fv(couleurNoir());
  glPushMatrix();
  manipulateurSouris();
  manipulateurClavier();
  switch ( obj ) {
    case 0  : glBegin(GL_POINTS) ;
              glVertex3f(-7.0F,4.0F,1.0F) ;
              glVertex3f(8.0F,-1.0F,-2.0F) ;
              glVertex3f(-3.0F,7.0F,3.0F) ;
              glVertex3f(-1.0F,-8.0F,0.0F) ;
              glVertex3f(2.0F,-4.0F,5.0F) ;
              glVertex3f(5.0F,8.0F,1.0F) ;
              glEnd() ;
              break ;
    case 1  : glBegin(GL_LINES) ;
              glVertex3f(-7.0F,4.0F,-1.0F) ;
              glVertex3f(8.0F,-1.0F,2.0F) ;
              glVertex3f(-3.0F,7.0F,0.0F) ;
              glVertex3f(-1.0F,-8.0F,4.0F) ;
              glVertex3f(2.0F,-4.0F,-2.0F) ;
              glVertex3f(5.0F,8.0F,3.0F) ;
              glEnd() ;
              break ;
    case 2  : glBegin(GL_LINE_STRIP) ;
              glVertex3f(-7.0F,4.0F,-1.0F) ;
              glVertex3f(8.0F,-1.0F,2.0F) ;
              glVertex3f(-3.0F,7.0F,0.0F) ;
              glVertex3f(-1.0F,-8.0F,4.0F) ;
              glVertex3f(2.0F,-4.0F,-2.0F) ;
              glVertex3f(5.0F,8.0F,3.0F) ;
              glEnd() ;
              break ;
    case 3  : glBegin(GL_LINE_LOOP) ;
              glVertex3f(-7.0F,4.0F,-1.0F) ;
              glVertex3f(8.0F,-1.0F,2.0F) ;
              glVertex3f(-3.0F,7.0F,0.0F) ;
              glVertex3f(-1.0F,-8.0F,4.0F) ;
              glVertex3f(2.0F,-4.0F,-2.0F) ;
              glVertex3f(5.0F,8.0F,3.0F) ;
              glEnd() ;
              break ;
    case 4  : glBegin(GL_POLYGON) ;
              glColor4fv(couleurBleu()) ;
              glVertex3f(-7.0F,4.0F,0.0F) ;
              glVertex3f(-3.0F,7.0F,0.0F) ;
              glVertex3f(5.0F,8.0F,0.0F) ;
              glVertex3f(8.0F,-1.0F,0.0F) ;
              glVertex3f(2.0F,-4.0F,0.0F) ;
              glVertex3f(-1.0F,-8.0F,0.0F) ;
              glEnd() ;
              break ;
    case 5  : glBegin(GL_QUADS) ;
              glColor4fv(couleurBleu()) ;
              glVertex3f(-7.0F,2.0F,1.0F) ;
              glVertex3f(-1.0F,7.0F,1.0F) ;
              glVertex3f(2.0F,6.0F,1.0F) ;
              glVertex3f(-6.0F,-3.0F,1.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(3.0F,-8.0F,-2.0F) ;
              glVertex3f(7.0F,-5.0F,-2.0F) ;
              glVertex3f(9.0F,2.0F,-2.0F) ;
              glVertex3f(1.0F,-3.0F,-2.0F) ;
              glEnd() ;
              break ;
    case 6  : glBegin(GL_QUAD_STRIP) ;
              glColor4fv(couleurBleu()) ;
              glVertex3f(-7.0F,5.0F,0.0F) ;
              glVertex3f(-3.0F,8.0F,0.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(-4.0F,-2.0F,0.0F) ;
              glVertex3f(0.0F,3.0F,0.0F) ;
              glColor4fv(couleurVert()) ;
              glVertex3f(2.0F,-2.5F,0.0F) ;
              glVertex3f(3.0F,5.0F,0.0F) ;
              glColor4fv(couleurCyan()) ;
              glVertex3f(8.5F,0.0F,0.0F) ;
              glVertex3f(8.0F,2.0F,0.0F) ;
              glEnd() ;
              break ;
    case 7  : glBegin(GL_TRIANGLES) ;
              glColor4fv(couleurBleu()) ;
              glVertex3f(-7.0F,-6.0F,2.0F) ;
              glVertex3f(-5.0F,7.0F,-4.0F) ;
              glVertex3f(2.0F,-5.0F,-1.0F) ;
              glColor4fv(couleurVert()) ;
              glVertex3f(-3.0F,8.0F,-5.0F) ;
              glVertex3f(7.0F,-5.0F,3.0F) ;
              glVertex3f(9.0F,7.0F,2.0F) ;
              glEnd() ;
              break ;
    case 8  : glBegin(GL_TRIANGLE_STRIP) ;
              glColor4fv(couleurBleu()) ;
              glVertex3f(-7.0F,5.0F,3.0F) ;
              glVertex3f(-3.0F,8.0F,2.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(-4.0F,-2.0F,-1.0F) ;
              glVertex3f(0.0F,3.0F,0.0F) ;
              glColor4fv(couleurVert()) ;
              glVertex3f(2.0F,-2.5F,5.0F) ;
              glVertex3f(3.0F,5.0F,3.0F) ;
              glColor4fv(couleurCyan()) ;
              glVertex3f(8.5F,0.0F,-1.0F) ;
              glVertex3f(8.0F,2.0F,-2.0F) ;
              glEnd() ;
              break ;
    case 9  : glBegin(GL_TRIANGLE_FAN) ;
              glColor4fv(couleurBleu()) ;
              glVertex3f(0.0F,7.0F,3.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(-7.0F,-2.0F,2.0F) ;
              glColor4fv(couleurVert()) ;
              glVertex3f(-4.0F,-6.0F,-1.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(-1.0F,-8.0F,0.0F) ;
              glColor4fv(couleurVert()) ;
              glVertex3f(1.0F,-1.0F,5.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(3.0F,-4.0F,3.0F) ;
              glColor4fv(couleurVert()) ;
              glVertex3f(6.0F,1.0F,-1.0F) ;
              glColor4fv(couleurRouge()) ;
              glVertex3f(8.0F,5.0F,-2.0F) ;
              glEnd() ; }
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void myinit (void) {
  glClearColor(1.0,1.0,1.0,1.0);
  glEnable(GL_DEPTH_TEST) ;
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 32   : obj++ ;
                  if ( obj == 10 )
                    obj = 0 ;
                  glutPostRedisplay();
                  break; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(200,200); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Primitives graphiques"); 
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-500.0,500.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