1

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

-在此代码块之前调用 get error -纹理是 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);
4

1 回答 1

0

您说图像是 24 位的,但在您编写的代码中:

if (nBPP == 32)

于 2013-09-03T13:41:22.357 回答