这是我的代码
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]);
有谁能够帮我?