- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
回答
在使用 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: 是的,图像位于正确的位置:
此外,我尝试使用完整路径,但没有帮助。
最佳答案
由于这似乎是 SOIL 而不是 GL 的问题,因此在调用 SOIL_load_image
后使用 SOIL_last_result
检查最后的 SOIL 错误。这应该可以让您更好地了解实际出了什么问题。
关于c++ - SOIL_load_image() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31237600/
回答 在使用 SOIL_last_result() 之后,正如 dcook 所建议的,我发现了两件事: 1) 如PaulMcKenzie 所说,它找不到图像,所以我的工作目录确实如genpfault
我是一名优秀的程序员,十分优秀!