1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
GLchar texturePath[128] = "images/512.jpg";
//unsigned char texture[512][512][3];
/********
* GLint loadTexture() - Charge une Texture jpeg
****/
unsigned char ***loadTexture(char *fichier, int l, int h, unsigned char **adresse){
/**
* Varriable Local */
unsigned char texture[l][h][3];
unsigned char image[l*h*3];
struct jpeg_decompress_struct jpegInfo;
struct jpeg_error_mgr jpegErreur;
FILE *file;
unsigned char *ligne;
int i, j;
/**
* Debut */
jpegInfo.err = jpeg_std_error(&jpegErreur);
jpeg_create_decompress(&jpegInfo);
if((file = fopen(fichier, "rb")) == NULL){
printf("Erreur: impossible d'ouvrire le fichier jpeg \"%s\"\n", fichier);
//exit(1);
}
jpeg_stdio_src(&jpegInfo, file);
jpeg_read_header(&jpegInfo, TRUE);
// On verifie si l'image est bien au format RGB
if(jpegInfo.jpeg_color_space == JCS_GRAYSCALE){
printf("Erreur: l'image doit etre encoder en RGB\n");
//exit(1);
}
// On verifie si l'image est de bonne taille
if((jpegInfo.image_width != l) || (jpegInfo.image_height != h)){
printf("Erreur: l'image n'est pas a la bonne taille\nLargeur:%d\nHauteur:%d\n", l, h);
//exit(1);
}
// - Tous c bien passez
jpeg_start_decompress(&jpegInfo);
ligne = image;
while(jpegInfo.output_scanline < jpegInfo.output_height){
ligne = image +3*h*jpegInfo.output_scanline;
jpeg_read_scanlines(&jpegInfo, &ligne, 1);
}
jpeg_finish_decompress(&jpegInfo);
jpeg_destroy_decompress(&jpegInfo);
// On formate le tableau de sortie pour OpenGL
for(i=0; i<h; i++){
for(j=0;j<l;j++){
texture[i][j][0] = image[i*h*3+j*3];
texture[i][j][1] = image[i*h*3+j*3+1];
texture[i][j][2] = image[i*h*3+j*3+2];
//printf("textureR:%d\ntextureG:%d\ntextureB:%d\n",texture[i][j][0],texture[i][j][0],texture[i][j][0]);
}
}
adresse = &&texture;
return (adresse);
} |
Partager