小编Hei*_*ski的帖子

使用OpenGL和DevIL调用glTextureParameteri时发生访问冲突

我正在尝试使用DevIL加载图像,然后创建纹理。我有一个名为的类Texture,并且正在构造函数中进行所有这些操作。一个有效的上下文已创建。第一次调用时遇到访问冲突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 …
Run Code Online (Sandbox Code Playgroud)

c++ opengl textures access-violation devil

3
推荐指数
1
解决办法
1314
查看次数

检查元素是否在两个向量中的最快方法

所以,认为我们有两个向量,vec1和vec2.什么是仅对元素执行某些操作的最快方法,这两个元素都在两个向量中.到目前为止,我已经做到了这一点.简单地说,我们如何更快地实现这一目标,或者有什么办法:

vector<Test*> vec1;
vector<Test*> vec2;

//Fill both of the vectors, with vec1 containing all existing 
//objects of Test, and vec2 containing some of them.


for (Test* test : vec1){

    //Check if test is in vec2
    if (std::find(vec2.begin(), vec2.end(), test) != vec2.end){

        //Do some stuff

    }

}
Run Code Online (Sandbox Code Playgroud)

c++ algorithm vector

3
推荐指数
1
解决办法
126
查看次数

标签 统计

c++ ×2

access-violation ×1

algorithm ×1

devil ×1

opengl ×1

textures ×1

vector ×1