尝试加载纹理时,SDL_Image返回NULL

时间:2014-04-20 01:26:16

标签: c++ texture-mapping opengl-3 sdl-2 sdl-image

我已将模型加载到我的屏幕上,但无法获得它的纹理读取。每当我尝试加载模型的纹理时,它都会返回NULL。模型和纹理位于同一目录中,我无法弄清楚程序出现问题的原因。程序运行时,我从IMG_GetError()收到的错误是:

  

无法打开(位置)/image.jpg

以下是它的加载方式:

bool CTexture::load()
{
    surface = IMG_Load(_fileName.c_str());

    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &_textureObj);

    if (surface == NULL)
    {
        std::cout 
        << "---------------\n" 
        << IMG_GetError() 
        << "\n---------------\n" 
        << std::endl;

        return 0;
    }

    _width = surface->w;
    _height = surface->h;
    _bpp = surface->pitch;

    if (surface->format->BytesPerPixel == 3)
        _mode = GL_RGB;

    else if (surface->format->BitsPerPixel == 4)
        _mode = GL_RGBA;

    else
    {
        SDL_FreeSurface(surface);
        return false;
    }

    glBindTexture(_textureTarget, _textureObj);
    glTexImage2D(_textureTarget, 0, _mode, surface->w, surface->h, 0, _mode, GL_UNSIGNED_BYTE, surface->pixels);
    setFiltering(GL_LINEAR, GL_LINEAR);

    _isLoaded = true;

    if (surface)
        SDL_FreeSurface(surface);

    std::cout << _fileName << std::endl;

    return _isLoaded;

}

我的DLL是 libjpeg-9,libpng16-16,libtiff和libwebp-4。

0 个答案:

没有答案