I am trying to upload an image file and use it as a texture for a cube. I use SDL_image to do this.

I used this image because I found it in various file formats (TGA, TIF, JPG, PNG, BMP)
Code:
SDL_Surface * texture;
texture = IMG_Load("/Users/Foo/Code/xcode/test/lena.bmp");
if(texture == NULL){
printf("bad image\n");
exit(1);
}
glGenTextures(1, &textureObjOpenGLlogo);
glBindTexture(GL_TEXTURE_2D, textureObjOpenGLlogo);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture-> pixels);
SDL_FreeSurface(texture);
The code compiles without errors and warnings!
I am tired of all file formats, but this always leads to a terrible result:

I use: SDL_image 1.2.9 and SDL 1.2.14 with Xcode 3.2 under 10.6.2
Does anyone know how to fix this?
source
share