I'm attempting to load a TGA file into memory and convert it to a HBITMAP so that I can draw it to the screen.
I'm having a problem where the colours that I see are not the same as the original TGA file.
I've double checked the file to ensure the correct one is being loaded, I've also double checked to ensure the TGA file is being loaded correctly into memory. I've also checked the TGA file with another program to see if it works and it does.
This is my code:
auto image = ReadImageFile("test.tga");
if (image == nullptr)
break;
unsigned int displayWidth = 1920;
unsigned int displayHeight = 1080;
BITMAPINFO bmi = {};
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = image->GetWidth();
bmi.bmiHeader.biHeight = -static_cast<int>(image->GetHeight());
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateDIBSection(hdcMem, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
if (hBitmap) {
SetDIBits(hdcMem, hBitmap, 0, image->GetHeight(), image->GetPixels(), &bmi, DIB_RGB_COLORS);
SelectObject(hdcMem, hBitmap);
SetStretchBltMode(hdc, HALFTONE);
StretchBlt(hdc, 0, 0, displayWidth, displayHeight, hdcMem, 0, 0, image->GetWidth(), image->GetHeight(), SRCCOPY);
DeleteObject(hBitmap);
}
DeleteDC(hdcMem);
EndPaint(pEventRecord->hWnd, &ps);
break;
Here are the properties of my TGA file:
Faces: 1
Pixel/Row Stride: 3
Mipmap Levels: 1
Image Width: 1920
Image Height: 1080
Bits Per Pixel: 24
Format: RGB
No Transparency
If I'm unable to resolve this then I am also open to using another approach to quickly load and display a TGA file.
Thank you.