How do I load textures to OpenGL using FreeImage library?

前端 未结 2 514
清酒与你
清酒与你 2021-02-03 12:36

I\'m learning OpenGL in C++ using NeHe tutorials, but I\'m trying to do them with FreeImage library, instead of Glaux or SOIL. The good point I see in using FreeImage is thar it

相关标签:
2条回答
  • 2021-02-03 12:50

    To extend the previous answer:

    FreeImage_GetBits() function will return a pointer to the data stored in a FreeImage-internal format. Where each scanline is usually aligned to a 4-bytes boundary. This will work fine while you have power-of-two textures. However, for NPOT textures you will need to specify the correct unpack alignment for OpenGL.

    There is another function in FreeImage which will allow you to get unaligned tightly packed array of pixels: FreeImage_ConvertToRawBits()

    0 讨论(0)
  • 2021-02-03 13:00

    There are two problems with your code - one is that you are converting to image to 32 bits but you specify a 24 bit texture format to openGL (GL_RGB). The second is that you are passing the FreeImage object itself to the texture rather than the converted bits.

    You need to do something like this instead

    FIBITMAP *pImage = FreeImage_ConvertTo32Bits(bitmap);
    int nWidth = FreeImage_GetWidth(pImage);
    int nHeight = FreeImage_GetHeight(pImage);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, nWidth, nHeight,
        0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)FreeImage_GetBits(pImage));
    
    FreeImage_Unload(pImage);
    
    0 讨论(0)
提交回复
热议问题