答案
在使用SOIL_last_result()之后,正如dcook所建议的那样,我发现了两件事:
1)它找不到图像,正如PaulMcKenzie所说,所以我的工作目录确实不正确,就像genpfault提到的那样。
2)设置完整路径后,它提到不支持我的jpeg格式(渐进式)。我将图像设置为标准的jpeg格式,它起了作用。
谢谢你的帮助!
原始问题
我目前正在尝试加载一个图像,使用土壤使用与OpenGL。但是,它似乎无法正确地加载图像,因为分配给它的变量最终为null。我试着看过这,但是当他设置属性时,他似乎放错了布局位置。我让它在每一行之后检查错误(glGetError()),但为了可读性,我在这里省略了。
OpenGL错误发生在带有GL_INVALID_VALUE的glTexImage2D()之后。这很可能是因为由于空映像,imgWidth/imgHeight比GL_MAX_TEXTURE_SIZE大。
输出:
null: 1
Max size: 3379
Width: 4298563
Height: 2686488
Obj: 1
GL_INVALID_VALUE - ../src/polygon.cpp:222代码:
// Generate the texture object and binds it.
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
// Texture image data
int imgWidth, imgHeight;
// Load the texture image.
unsigned char* image = SOIL_load_image("potato.jpg",
&imgWidth,
&imgHeight,
0,
SOIL_LOAD_RGB);
std::cout << "null: " << !image << std::endl;
std::cout << "Max size: " << GL_MAX_TEXTURE_SIZE << std::endl;
std::cout << "Width: " << imgWidth << std::endl;
std::cout << "Height: " << imgHeight << std::endl;
std::cout << "Obj: " << m_texture << std::endl;
// Generate the texture to the currently bound texture object.
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGB,
imgWidth,
imgHeight,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
image);
// Generate the mipmap to the currently bound texture object.
glGenerateMipmap(GL_TEXTURE_2D);
// Unbind and free image data.
SOIL_free_image_data(image);
glBindTexture(GL_TEXTURE_2D, 0);如果需要更多的数据,请告诉我。谢谢!
编辑1:是的,图像在正确的位置:

另外,我试着使用一条完整的路径,但没有帮助。
发布于 2015-07-06 16:40:41
由于这似乎是一个土壤问题,而不是GL,请在调用SOIL_last_result后用SOIL_load_image检查最后一个土壤错误。这应该会给你一个更好的线索,知道到底出了什么问题。
发布于 2020-02-18 17:04:44
我也有过同样的问题。解决方案是将完整路径设置为文件,如
C:/TestProjectsCPP/OpenGLTutorials/OpenGLTutorials/res/images/image1.jpg 在这个图像被加载并显示之后。
https://stackoverflow.com/questions/31237600
复制相似问题