这是我的代码
typedef struct Texture
{
GLubyte *Data;
GLuint bpp;
GLuint width, height;
GLuint ID;
}Texture;
class TextureLoader
{
public:
TextureLoader()
{
ilInit();
iluInit();
}
void load(ILenum FileType, const char *filename, Texture *texture)
{
ilLoad(FileType, filename);
texture->width = ilGetInteger(IL_IMAGE_WIDTH);
texture->height = ilGetInteger(IL_IMAGE_HEIGHT);
texture->bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
texture->Data = ilGetData();
ilEnable(IL_CONV_PAL);
unsigned int type = ilGetInteger(IL_IMAGE_FORMAT);
glGenTextures(1, &texture->ID);
glBindTexture(GL_TEXTURE_2D,texture->ID);
gluBuild2DMipmaps(GL_TEXTURE_2D, texture->bpp, texture->width,
texture->height, type, GL_UNSIGNED_BYTE, texture->Data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
}
}Loader;
而且似乎不起作用
调用gluBuild2DMipmaps后出现分段错误
我不明白什么是问题,因为代码大多是从一个示例中复制粘贴的(。。。这是对TextureLoader::load:的调用
vector <Texture> bgtextures;
bgtextures.resize(1);
Loader.load(IL_JPG,"bgsnow.jpg",&bgtextures[0]);
有人能帮我吗?
看看这个的返回值:
ilLoad(FileType, filename);
通过执行以下代码:
if (ilLoad(FileType, filename) == IL_FALSE) {
//Make it produce an error or something.
}
正如genpfault所建议的,您可能传入了一个不正确的文件名。