J'essaie de charger un fichier image et de l'utiliser comme texture pour un cube. J'utilise SDL_image pour le faire.SDL_image/C++ Programme OpenGL: IMG_Load() produit des images floues
original image http://i33.tinypic.com/2i1f3bp.jpg
J'ai utilisé cette image parce que je l'ai trouvé dans divers formats de fichiers (tga, TIF, jpg, png, bmp)
Le code:
SDL_Surface * texture;
//load an image to an SDL surface (i.e. a buffer)
texture = IMG_Load("/Users/Foo/Code/xcode/test/lena.bmp");
if(texture == NULL){
printf("bad image\n");
exit(1);
}
//create an OpenGL texture object
glGenTextures(1, &textureObjOpenGLlogo);
//select the texture object you need
glBindTexture(GL_TEXTURE_2D, textureObjOpenGLlogo);
//define the parameters of that texture object
//how the texture should wrap in s direction
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
//how the texture should wrap in t direction
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//how the texture lookup should be interpolated when the face is smaller than the texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//how the texture lookup should be interpolated when the face is bigger than the texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//send the texture image to the graphic card
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture-> pixels);
//clean the SDL surface
SDL_FreeSurface(texture);
Le code compile sans erreurs ni avertissements!
J'ai fatigué tous les formats de fichiers, mais cela produit toujours ce résultat laid:
result http://i34.tinypic.com/ipbpxe.jpg
J'utilise: SDL_image 1.2.9 & SDL 1.2.14 avec XCode 3.2 sous 10.6.2
Est-ce que quelqu'un sait comment résoudre ce problème?
À noter: La raison pour laquelle vous trouvez cette image dans de nombreux formats est parce que c'est l'image standard pour les tests de compression d'image. "Lenna" est le nom de l'image et le nom du modèle est Lena Soderberg. L'histoire de l'image est assez intéressante. – greyfade