L'exécutable

Image.raw - Damier.raw

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

Fichier source : Texturage.cpp

static const float noir[] = { 0.0F,0.0F,0.0F,1.0F };
static const float blanc[] = { 1.0F,1.0F,1.0F,1.0F };

/* Fonction d'initialisation des parametres     */
/* OpenGL ne changeant pas au cours de la vie   */
/* du programme                                 */

static int fileSize(char *filename) {
  struct _finddata_t c_file;
  intptr_t hFile;
  if( (hFile = _findfirst(filename,&c_file)) == -1L )
    return(-1);
  int size = c_file.size;
  _findclose(hFile);
  return(size);
}

static unsigned char *loadRawImage(char *filename) {
  int size = fileSize(filename);
  if ( size == -1 )
    return(NULL);
  unsigned char *img =(unsigned char *) malloc(size);
  if ( !img )
    return(NULL);
  FILE *f = fopen(filename,"rb");
  if ( !f ) {
    free(img);
    return(NULL); }
  fread(img,1,size,f);
  fclose(f);
  return(img);


static void init(void) {
  const GLfloat shininess[] = { 50.0 };
  glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,noir);
  glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,blanc);
  glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,noir);
  glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shininess);
  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_LIGHT2);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_AUTO_NORMAL);
  glPixelStorei(GL_UNPACK_ALIGNMENT,1); 
  { unsigned char *img = loadRawImage("Image.raw");
    glTexImage2D(GL_TEXTURE_2D,0,3,64,64,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); 
}

/* Scene affichee                               */

static void scene() {
  glPushMatrix();
  glBegin(GL_QUADS);
  glTexCoord2f(0.0F,0.0F);
  glVertex2f(2.0F,2.0F);
  glTexCoord2f(1.0F,0.0F);
  glVertex2f(-2.0F,2.0F);
  glTexCoord2f(1.0F,1.0F);
  glVertex2f(-2.0F,-2.0F);
  glTexCoord2f(0.0F,1.0F);
  glVertex2f(2.0F,-2.0F);
  glEnd();
  glPopMatrix();
}

RETOUR