1

我在使用 DevIL 1.7.8 读取图像时遇到问题。到目前为止,我知道以下代码段应该可以工作:

ilInit();
ILuint ImageName;
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
wchar_t* imgFilename = L"..\\..\\resources\\textures\\red.png"; 
ilLoadImage(imgFilename);
ILubyte* texture = ilGetData();

当我检查第一个像素时

for (int i=0; i<64; i++) cout << (int)texture[i] << endl;

我得到一个非常随机的输出。图片实际上是完全红色的。

我也尝试使用 ilut

ilutRenderer(ILUT_OPENGL);
GLuint t = ilutGLLoadImage(L"..\\..\\resources\\textures\\red.png");

但实际上我什至不能包含相应的头文件,因为在该头文件中链接了 il.h,它应该位于不存在的文件夹 (\IL) 中。即使我创建此文件夹并将所需的头文件复制到其中,我也会遇到编译错误。

任何人都可以帮助我使用 DevIL 吗?

4

1 回答 1

0

我正在阅读这样的图像和绑定纹理:

ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT); // set [0,0] of texture to bottom left corner

ilImage image;
GLuint ind;
glGenTextures(1, &ind);
glBindTexture(GL_TEXTURE_2D, ind);
image.Load(L"<path>");//  or just name.format  be sure to have image in correct folder.

渲染时,需要先绑定正确的纹理:

glBindTexture(GL_TEXTURE_2D, ind);

然后将纹理的 UV 坐标分配给顶点:

glTexCoord2f(x1, y1);               
glVertex3f(x, y, z);

不要忘记启用 GL_TEXTURE_2D 或您正在使用的任何类型。

于 2015-05-02T23:47:43.473 回答