我试图用DevIL加载图像,然后创建一个纹理。我有一个名为Texture
的类,我在构造函数中完成了所有这些工作。一个有效的上下文已经创建。我在第一次致电glTextureParameteri()
时遇到了访问冲突,所以我猜想纹理没有正确绑定。我只看到没有理由为什么它不会绑定。使用OpenGL和DevIL调用glTextureParameteri时的访问冲突
这里的构造函数:
Texture::Texture(const std::string& filename){
//DevIL handle for the image
unsigned int ilID;
ilGenImages(1, &ilID);
ilBindImage(ilID);
ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
if (!ilLoad(IL_BMP, (ILstring)filename.c_str())){
DebugUtility::gl_log_err("Failed to load image &s\n", filename.c_str()); //Just function that prints to log file
return;
}
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glGenTextures(1, &texture);
//"texture" is global GLuint
glBindTexture(GL_TEXTURE_2D, texture);
//LINE BELOW CAUSES ACCESS VIOLATION!
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
0, GL_RGBA, GL_UNSIGNED_BYTE, ilGetData());
ilDeleteImages(1, &ilID);
//Again, prints to log file
DebugUtility::gl_log("Succefully loaded and created texture %s", filename.c_str());
}
ilLoad
返回true,因为不执行,如果块中的代码。这里是错误(我正在使用Visual Studio 2013):
projectSDL.exe中0x74E1CB49未处理的异常:0xC0000005:执行位置0x00000000的访问冲突。
'glTextureParameter()'在OpenGL 4.5中是标准的。我希望人们第一次看到它时会把它和glTexParameter()混淆起来。有时你想知道OpenGL中的API设计选择...... – 2014-10-27 15:14:01
工作!事实上,容易搞砸那些功能... – Heiski 2014-10-27 15:17:33