0

回答

SOIL_last_result()按照dcook建议使用后,我发现了两件事:

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

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

谢谢您的帮助!


原始问题

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

OpenGL 错误发生glTexImage2D()GL_INVALID_VALUE. 这很可能是因为imgWidth/imgHeightGL_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目录

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

4

2 回答 2

3

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

于 2015-07-06T16:40:41.647 回答
0

我遇到过同样的问题。解决方案是设置文件的完整路径,例如

C:/TestProjectsCPP/OpenGLTutorials/OpenGLTutorials/res/images/image1.jpg 

加载并显示此图像后。

于 2020-02-18T17:04:44.640 回答