首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SOIL_load_image()返回null

SOIL_load_image()返回null
EN

Stack Overflow用户
提问于 2015-07-06 04:01:40
回答 2查看 4.5K关注 0票数 0

答案

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

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

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

谢谢你的帮助!

原始问题

我目前正在尝试加载一个图像,使用土壤使用与OpenGL。但是,它似乎无法正确地加载图像,因为分配给它的变量最终为null。我试着看过,但是当他设置属性时,他似乎放错了布局位置。我让它在每一行之后检查错误(glGetError()),但为了可读性,我在这里省略了。

OpenGL错误发生在带有GL_INVALID_VALUEglTexImage2D()之后。这很可能是因为由于空映像,imgWidth/imgHeightGL_MAX_TEXTURE_SIZE大。

输出:

代码语言:javascript
复制
null: 1
Max size: 3379
Width: 4298563
Height: 2686488
Obj: 1
GL_INVALID_VALUE - ../src/polygon.cpp:222

代码:

代码语言:javascript
复制
    // 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:是的,图像在正确的位置:

另外,我试着使用一条完整的路径,但没有帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-06 16:40:41

由于这似乎是一个土壤问题,而不是GL,请在调用SOIL_last_result后用SOIL_load_image检查最后一个土壤错误。这应该会给你一个更好的线索,知道到底出了什么问题。

票数 3
EN

Stack Overflow用户

发布于 2020-02-18 17:04:44

我也有过同样的问题。解决方案是将完整路径设置为文件,如

代码语言:javascript
复制
C:/TestProjectsCPP/OpenGLTutorials/OpenGLTutorials/res/images/image1.jpg 

在这个图像被加载并显示之后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31237600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档