L'exécutable

Image401.gif (2718 octets) Image401.gif (2718 octets)

Image401.gif (2718 octets) Image401.gif (2718 octets)

Image401.gif (2718 octets)

Le source: Stipple.cpp

/* Auteur: Nicolas JANEY         */
/* nicolas.janey@univ-fcomte.fr  */
/* Avril 2001                    */
/* Les motifs en 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 ;
static GLubyte fly[] = {
  0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,
  0x03,0x80,0x01,0xC0,
  0x06,0xC0,0x03,0x60,
  0x04,0x60,0x06,0x20,
  0x04,0x30,0x0C,0x20,
  0x04,0x18,0x18,0x20,
  0x04,0x0C,0x30,0x20,
  0x04,0x06,0x60,0x20,
  0x44,0x03,0xC0,0x22,
  0x44,0x01,0x80,0x22,
  0x44,0x01,0x80,0x22,
  0x44,0x01,0x80,0x22,
  0x44,0x01,0x80,0x22,
  0x44,0x01,0x80,0x22,
  0x44,0x01,0x80,0x22,
  0x66,0x01,0x80,0x66,
  0x33,0x01,0x80,0xCC,
  0x19,0x81,0x81,0x98,
  0x0C,0xC1,0x83,0x30,
  0x07,0xe1,0x87,0xe0,
  0x03,0x3f,0xfc,0xc0,
  0x03,0x31,0x8c,0xc0,
  0x03,0x33,0xcc,0xc0,
  0x06,0x64,0x26,0x60,
  0x0c,0xcc,0x33,0x30,
  0x18,0xcc,0x33,0x18,
  0x10,0xc4,0x23,0x08,
  0x10,0x63,0xC6,0x08,
  0x10,0x30,0x0c,0x08,
  0x10,0x18,0x18,0x08,
  0x10,0x00,0x00,0x08};
static GLubyte uni[] = {
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF};
static GLubyte ray[] = {
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22,
  0x33,0x22,0x33,0x22} ;

void display(void) {
  glClearColor (1.0,1.0,1.0,1.0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glColor4fv(couleurNoir());
  glPushMatrix();
  manipulateurSouris();
  manipulateurClavier();
  switch ( obj ) {
    case 0  : glPointSize(10.0f);
              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() ;
              glPointSize(1.0f);
              break ;
    case 1  : glLineWidth(10.0f);
              glBegin(GL_LINES) ;
              glVertex3f(-7.0F,4.0F,-1.0F) ;
              glVertex3f(8.0F,-1.0F,2.0F) ;
              glEnd() ;
              glLineWidth(5.0f);
              glBegin(GL_LINES) ;
              glVertex3f(-3.0F,7.0F,0.0F) ;
              glVertex3f(-1.0F,-8.0F,4.0F) ;
              glEnd() ;
              glLineWidth(2.0f);
              glBegin(GL_LINES) ;
              glVertex3f(2.0F,-4.0F,-2.0F) ;
              glVertex3f(5.0F,8.0F,3.0F) ;
              glEnd() ;
              glLineWidth(1.0f);
              break ;
    case 2  : glLineStipple(1,0x3456);
              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() ;
              glLineStipple(1,0xFFFF);
              break ;
    case 3  : glLineStipple(10,0x3456);
              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() ;
              glLineStipple(1,0xFFFF);
              break ;
    case 4  : glPolygonStipple(fly);
              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() ;
              glPolygonStipple(uni);
              break ;
    case 5  : glPolygonStipple(ray);
              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() ;
              glPolygonStipple(uni);
              break ;
    case 6  : glPolygonMode(GL_FRONT,GL_LINE);
              glPolygonMode(GL_BACK,GL_POINT);
              glPointSize(5.0f);
              glLineWidth(2.0f);
              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() ;
              glPointSize(1.0f);
              glLineWidth(1.0f);
              glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
              break ;
    case 7  : glEnable(GL_CULL_FACE);
              glCullFace(GL_FRONT);
              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() ;
              glCullFace(GL_NONE);
              glDisable(GL_CULL_FACE);
              break ;
    case 8  : glEnable(GL_CULL_FACE);
              glCullFace(GL_BACK);
              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() ;
              glDisable(GL_CULL_FACE);
              break ;
    case 9  : glPolygonMode(GL_FRONT,GL_LINE);
              glPolygonMode(GL_BACK,GL_FILL);
              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() ;
              glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); }
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void myinit (void) {
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LINE_STIPPLE);
  glEnable(GL_POLYGON_STIPPLE);
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case ' '  : obj = (obj+1)%10 ;
                  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("Attributs de dessin"); 
  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