回答
SOIL_last_result()
按照dcook
建议使用后,我发现了两件事:
1)如前所述,它找不到图像,PaulMcKenzie
因此我的工作目录确实不正确。genpfault
2)设置完整路径后,它提到我的jpeg格式(渐进式)不支持。我将图像设置为标准的 jpeg 格式并且它工作。
谢谢您的帮助!
原始问题
我目前正在尝试使用 SOIL 加载图像以与 OpenGL 一起使用。但是,它似乎无法正确加载图像,因为分配给它的变量最终为空。我试过看这个,但似乎这个人在设置属性时只是放错了布局位置。我让它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:是的,图像位于正确的位置:
另外,我尝试使用完整路径,但没有帮助。