 
  
    
Fichier source : TextureBitmapCylindre.cpp
/* Fonction d'initialisation des parametres     */
    /* OpenGL ne changeant pas au cours de la vie   */
    /* du programme                                 */
    /* Contient en particulier l'initialisation     */
    /* d'une texture 2D                             */
    
    static void init(void) {
      const GLfloat mat_shininess[] = { 50.0 };
      glMaterialfv(GL_FRONT,GL_SPECULAR,blanc);
      glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
      glLightfv(GL_LIGHT0,GL_DIFFUSE,gris);
      glLightfv(GL_LIGHT1,GL_DIFFUSE,gris);
      glLightfv(GL_LIGHT2,GL_DIFFUSE,gris);
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
      glEnable(GL_LIGHT2);
      glDepthFunc(GL_LESS);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_NORMALIZE);
      glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);
      glEnable(GL_TEXTURE_2D);
      glPixelStorei(GL_UNPACK_ALIGNMENT,1); 
      { int rx;
        int ry;
        unsigned char *img = chargeImagePng("Test.png",&rx,&ry);
        if ( img ) {
          glTexImage2D(GL_TEXTURE_2D,0,3,rx,ry,0,GL_RGB,GL_UNSIGNED_BYTE,img);
          free(img); } }
      glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); 
      glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
      glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); 
      glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); 
    }
    
    /* Modelisation par facettes                    */
    /* d'un cylindre texturable                     */
    
    #ifndef M_PI
    #define M_PI 3.14159
    #endif
    
    static void mySolidCylindre(double hauteur,double rayon,int ns) {
      GLboolean nm = glIsEnabled(GL_NORMALIZE);
      if ( !nm )
        glEnable(GL_NORMALIZE);
      float normale[4];
      glGetFloatv(GL_CURRENT_NORMAL,normale);
      glPushMatrix();
      hauteur /= 2.0F;
      glBegin(GL_QUAD_STRIP);
      for( int 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;
        float s =(float) i/ns;
        glTexCoord2f(s,1.0F);
        glVertex3f(x,hauteur,z);
        glTexCoord2f(s,0.0F);
        glVertex3f(x,-hauteur,z); }
      glEnd();
      glPopMatrix();
      glNormal3f(normale[0],normale[1],normale[2]);
      if ( !nm )
        glDisable(GL_NORMALIZE);
    }
    
    /* Scene dessinee                               */
    
    static void scene(void) {
      glPushMatrix();
      mySolidCylindre(5.0,2.5,72);
      glPopMatrix();
    }