SOIL加载一些图像,有些则没有

时间:2017-06-17 09:45:49

标签: c++ visual-studio soil

我从未在使用SOIL加载图像时出现问题,但现在它无法正确读取图像。大多数人仍在工作。我将工作图像与无法加载的图像进行了比较,它们的属性完全相同。读取时实际上不会发生错误,它出现在这里:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

我从文件加载纹理的方法是:

GLint TextureFromFile(const char* path, string directory)
{
//Generate texture ID and load texture data 
string filename = string(path);
filename = directory + '/' + filename;

GLuint textureID;
glGenTextures(1, &textureID);
int width, height;
unsigned char* image = SOIL_load_image(filename.c_str(), &width, &height, 0, SOIL_LOAD_RGB);
// Assign texture to ID
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);

// Parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
SOIL_free_image_data(image);

return textureID;
}

调试时我注意到,当纹理加载工作时,* image包含一个字符串 working debug_tex 如果它不起作用,字符串看起来像这样: not working debug_tex

我希望我能很好地解释我的问题。有什么想法吗?

0 个答案:

没有答案
相关问题