我正在尝试加载图像文件并将其用作立方体的纹理。我正在使用 SDL_image 来做到这一点。
我使用这张图片是因为我发现它有各种文件格式(tga、tif、jpg、png、bmp)
编码 :
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);
代码编译没有错误或警告!
我已经厌倦了所有文件格式,但这总是会产生丑陋的结果:
我正在使用:SDL_image 1.2.9 和 SDL 1.2.14,XCode 3.2 在 10.6.2 下
有谁知道如何解决这个问题?