OpenGL FreeImage纹理加载错误

时间:2013-08-28 17:19:26

标签: opengl textures loading freeimage

目前,我的渲染工作除了纹理渲染完全黑色。我在这段代码中调用glTexture2D后立即收到错误1380或GL_INVALID_ENUM。我已经尝试了所有我能想到的东西,但错误不会消失。

在此代码块之前立即收到错误 - 纹理的功率为2(128 x 128) - 使用新的24位photoshop .bmp

    glEnable(GL_TEXTURE_2D);

    FREE_IMAGE_FORMAT imageFormat = FreeImage_GetFileType(filename, 0);
    FIBITMAP* bmpImage = FreeImage_ConvertTo32Bits(FreeImage_Load(imageFormat, filename));

    int width = FreeImage_GetWidth(bmpImage);
    int height = FreeImage_GetHeight(bmpImage);
    int nBPP =  FreeImage_GetBPP(bmpImage);

    if (nBPP == 32)
    {
        // Generate an ID for the texture.
        glGenTextures(1, &m_texture);

        // Bind the texture as a 2D texture.
        glBindTexture(GL_TEXTURE_2D, m_texture);

        // Load the image data into the texture unit.
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)FreeImage_GetBits(bmpImage));

        if(auto temp = glGetError())
        {
            // GL_INVALID_ENUM/1380 here
        }
    }

    FreeImage_Unload(bmpImage);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

1 个答案:

答案 0 :(得分:0)

你说图像是24位,但在你的代码中你写道:

if (nBPP == 32)

相关问题