I have some code that loads GIF files as texture maps. It all works well, but I can’t get the transparency information to come through to the final image.
Here’s some code extracts…
// Load image - OleLoadPicturePath supports most common picture formats...
HRESULT hr = OleLoadPicturePath(wszPath, 0, 0, 0, IID_IPicture, (void**)&pPicture);
... in here, I do a bit of scaling to get 2^x dimensions for m_iWidth and m_iHeight
// Now Create A Temporary Bitmap
BITMAPINFO bi = {0};
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biWidth = m_iWidth;
bi.bmiHeader.biHeight = m_iHeight;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biPlanes = 1;
hbmpTemp = CreateDIBSection(hdcTemp, &bi, DIB_RGB_COLORS, (void**)&pBits, 0, 0);
// Render GIF image onto bitmap
SelectObject(hdcTemp, hbmpTemp);
pPicture->Render(hdcTemp, 0, 0, m_iWidth, m_iHeight, 0, lHeight, lWidth, -lHeight, 0);
// .. then do a bit of
for(long i = 0; i < m_iWidth * m_iHeight; i++) {
pPixel = (BYTE *)&(pBits[i]);
temp = pPixel[0];
pPixel[0] = pPixel[2];
pPixel[2] = temp;
pPixel[3] = 255; // Set The Alpha Value
}
So, in a nutshell, it’s pretty straightforward. But, I think the problem is that Render doesn’t set the alpha values, because the final bitmap always comes out with alpha values of zero. The GIF transparency is definitely loaded, because when I force the alpha to 255, the texture shows black in the transparent sections of the GIF.
Is there a simple way to get the GIF transparency to carry through to the alpha channel of the bitmap and texture?
Perhaps by defining the bitmap a different way, the Render() will correctly render the alpha values as well as the colours?
Otherwise, I can manually test the pixel colour when setting the alpha values, and get the transparency that way, but I’d rather do it properly if I can.
Thanks!