gpt4 book ai didi

c++ - SOIL_load_image() 返回 null

转载 作者:行者123 更新时间:2023-11-28 02:24:21 25 4
gpt4 key购买 nike

回答

在使用 SOIL_last_result() 之后,正如 dcook 所建议的,我发现了两件事:

1) 如PaulMcKenzie 所说,它找不到图像,所以我的工作目录确实如genpfault 所述不正确。

2) 在我设置完整路径后,它提到我的 jpeg 格式(渐进式)不受支持。我将图像设置为标准的 jpeg 格式并且它起作用了。

感谢您的帮助!


原始问题

我目前正在尝试使用 SOIL 加载图像以与 OpenGL 一起使用。但是,它似乎无法正确加载图像,因为分配给它的变量最终为空。我试过查看 this但似乎这家伙在设置属性时只是把布局位置放错了。我让它在每一行之后检查错误(glGetError()),但为了便于阅读,我在这里省略了它。

OpenGL 错误发生在 glTexImage2D() 之后,带有 GL_INVALID_VALUE。这很可能是因为 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: 是的,图像位于正确的位置: bin directory

此外,我尝试使用完整路径,但没有帮助。

最佳答案

由于这似乎是 SOIL 而不是 GL 的问题,因此在调用 SOIL_load_image 后使用 SOIL_last_result 检查最后的 SOIL 错误。这应该可以让您更好地了解实际出了什么问题。

关于c++ - SOIL_load_image() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31237600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com