L'exécutable

Image.raw - Damier.raw

TP07-02-01.png TP07-02-02.png

TP07-03-01.png TP07-03-02.png

Fichier source : TexturageCubeCylindre.cpp

static void solidCube(double ct) {
  float c =(float) ct/2.0F;
  glBegin(GL_QUADS);
  { glNormal3f(0.0F,0.0F,-1.0F);
    glTexCoord2f(1.0F,0.0F);
    glVertex3f( c, c,-c);
    glTexCoord2f(1.0F,1.0F);
    glVertex3f( c,-c,-c);
    glTexCoord2f(0.0F,1.0F);
    glVertex3f(-c,-c,-c);
    glTexCoord2f(0.0F,0.0F);
    glVertex3f(-c, c,-c); }
  { glNormal3f(0.0F,0.0F,1.0F);
    glTexCoord2f(0.0F,0.0F);
    glVertex3f( c, c, c);
    glTexCoord2f(1.0F,0.0F);
    glVertex3f(-c, c, c);
    glTexCoord2f(1.0F,1.0F);
    glVertex3f(-c,-c, c);
    glTexCoord2f(0.0F,1.0F);
    glVertex3f( c,-c, c); }
  { glNormal3f(-1.0F,0.0F,0.0F);
    glTexCoord2f(0.0F,0.0F);
    glVertex3f(-c, c,-c);
    glTexCoord2f(1.0F,0.0F);
    glVertex3f(-c,-c,-c);
    glTexCoord2f(1.0F,1.0F);
    glVertex3f(-c,-c, c);
    glTexCoord2f(0.0F,1.0F);
    glVertex3f(-c, c, c); }
  { glNormal3f(1.0F,0.0F,0.0F);
    glTexCoord2f(0.0F,0.0F);
    glVertex3f( c, c, c);
    glTexCoord2f(1.0F,0.0F);
    glVertex3f( c,-c, c);
    glTexCoord2f(1.0F,1.0F);
    glVertex3f( c,-c,-c);
    glTexCoord2f(0.0F,1.0F);
    glVertex3f( c, c,-c); }
  { glNormal3f(0.0F,-1.0F,0.0F);
    glTexCoord2f(0.0F,0.0F);
    glVertex3f(-c,-c, c);
    glTexCoord2f(1.0F,0.0F);
    glVertex3f(-c,-c,-c);
    glTexCoord2f(1.0F,1.0F);
    glVertex3f( c,-c,-c);
    glTexCoord2f(0.0F,1.0F);
    glVertex3f( c,-c, c); }
  { glNormal3f(0.0F,1.0F,0.0F);
    glTexCoord2f(0.0F,0.0F);
    glVertex3f( c, c, c);
    glTexCoord2f(1.0F,0.0F);
    glVertex3f( c, c,-c);
    glTexCoord2f(1.0F,1.0F);
    glVertex3f(-c, c,-c);
    glTexCoord2f(0.0F,1.0F);
    glVertex3f(-c, c, c); }
  glEnd();
}

#ifndef M_PI
#define M_PI 3.14159
#endif

static void solidCylindre(double hauteur,double rayon,int ns) {
  float h = hauteur/2;
  glBegin(GL_QUAD_STRIP);
  forint i = 0 ; i <= ns ; i++ ) {
    float a = (2*M_PI*i)/ns;
    float cs = cos(a);
    float sn = -sin(a);
    glNormal3f(cs,0.0F,sn);
    float x = rayon*cs;
    float z = rayon*sn;
    glTexCoord2f((float) i/ns,0.0F);
    glVertex3f(x,h,z);
    glTexCoord2f((float) i/ns,1.0F);
    glVertex3f(x,-h,z); }
  glEnd();
  glBegin(GL_POLYGON);
  glNormal3f(0.0F,1.0F,0.0F);
  forint i = 0 ; i < ns ; i++ ) {
    float a = (2*M_PI*i)/ns;
    float cs = cos(a);
    float sn = -sin(a);
    float x = rayon*cs;
    float z = rayon*sn;
    glTexCoord2f(cs/4.0F,-sn/4.0F);
    glVertex3f(x,hauteur/2.0F,z); }
  glEnd();
  glBegin(GL_POLYGON);
  glNormal3f(0.0F,-1.0F,0.0F);
  forint i = 0 ; i < ns ; i++ ) {
    float a = (2*M_PI*i)/ns;
    float cs = cos(a);
    float sn = sin(a);
    float x = rayon*cs;
    float z = rayon*sn;
    glTexCoord2f(cs/4.0F,sn/4.0F);
    glVertex3f(x,-hauteur/2.0F,z); }
  glEnd();
}

RETOUR