加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SDL_image / C OpenGL程序:IMG_Load()生成模糊图像

发布时间:2020-12-16 10:16:01 所属栏目:百科 来源:网络整理
导读:我正在尝试加载图像文件并将其用作多维数据集的纹理.我正在使用SDL_image来做到这一点. original image http://i33.tinypic.com/2i1f3bp.jpg 我用这个图像是因为我发现它有各种文件格式(tga,tif,jpg,png,bmp) 代码 : SDL_Surface * texture;//load an image
我正在尝试加载图像文件并将其用作多维数据集的纹理.我正在使用SDL_image来做到这一点.

original image http://i33.tinypic.com/2i1f3bp.jpg

我用这个图像是因为我发现它有各种文件格式(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 imagen");
    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,GL_RGBA,texture->w,texture->h,GL_RGB,GL_UNSIGNED_BYTE,texture-> pixels);

//clean the SDL surface
SDL_FreeSurface(texture);

代码编译没有错误或警告!

我已经厌倦了所有的文件格式,但这总会产生丑陋的结果:

result http://i34.tinypic.com/ipbpxe.jpg

我正在使用:SDL_image 1.2.9& SDL 1.2.14,XCode 3.2低于10.6.2

有谁知道如何解决这个问题?

解决方法

图像失真的原因是因为它不是您指定的RGBA格式.检查 texture->format以找出它所在的格式并选择代表格式的相应GL_常量. (或者,将其转换为您选择的格式.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读