First, the GL_RGBA have one byte for each of Red, Green, Blue and Alpha (Alpha=transparency). Your code apparently didn't deal with alpha (the 4th byte of a pixel). Try to add the following line:
for (int pix = 0; pix<FreeImage_GetWidth(dib) * FreeImage_GetHeight(dib); pix++)
{
bits[pix * 4 + 0] = pixels[pix * 4 + 2];
bits[pix * 4 + 1] = pixels[pix * 4 + 1];
bits[pix * 4 + 2] = pixels[pix * 4 + 0];
bits[pix * 4 + 3] = pixels[pix * 4 + 3]; // Add this line to copy Alpha
}
Second, if it still doesn't work, try to remove the FreeImage_ConvertTo24Bits
line (even if it works please also try to remove this):
// dib = FreeImage_ConvertTo24Bits(dib); // Remove this line
if (FreeImage_GetBPP(dib) != 32)
{
FIBITMAP* tempImage = dib;
dib = FreeImage_ConvertTo32Bits(tempImage);
}
It's strange to convert the image to 24 bits then back to 32 bits. Maybe it will discard the alpha channel.
I didn't tried to run the whole program and debug it. Just providing some hints that you can try.