Original Post
Im making a game that runs windowed mode and so has to be able to run under 16 and 32 bit modes. At the moment i am simply creating a surface and filling it in with a colour (55, 7, 7) and then displaying it to the screen. I choose the colour from the Photoshops pallette and so know what to expect from the values inputted above. All is fine in 32 bit mode but in 16bit mode the colour displayed is not the correct colour. After "printscreen"ing the displayed colour and re-examining it within photoshop i see that the colour values are totally different. Ive checked that my video card runs in 565 16bit mode so the defined macro below should be correct.
Here is the relevant code.
//Macros
#define RGB_32BIT(r, g, b) ((r << 16) | (g << 8) | (b))
#define RGB_16BIT565(r, g, b) ((r << 11) | (g << 5) | (b))
//Function to take 3 colour components and then combine them according to current bitdepth of display and fill surface with the combined colour.
void SurfaceFillColour(LPDIRECTDRAWSURFACE7 lpDDSSurface, char red, char green, char blue)
{
DDBLTFX fx; //fx structure to hold fill colour
DDPIXELFORMAT ddpf;
//clear out structures
ZeroMemory(&ddpf, sizeof( ddpf ));
ZeroMemory(&fx, sizeof ( fx));
//initialise the sizes
ddpf.dwSize = sizeof( ddpf );
fx.dwSize = sizeof(fx);
//detect the bitdepth of the given surface
//Get the bit-depth of the surface, so we fill in different
//bit-depths correctly
lpDDSSurface->GetPixelFormat(&ddpf);
//combine colours depending on bitdepth of given surface
switch (ddpf.dwRGBBitCount)
{
case 16: //if its 16bit 565mode per pixel
fx.dwFillColor = RGB_16BIT565(red, green, blue);
break;
case 32: //if its 32bit per pixel
fx.dwFillColor = RGB_32BIT(red, green, blue);
break;
default : throw "This game only supports bitdepths of 16 and 32. Please change accordingly under Windows Display Settings (Right click on desktop)";
}
//and apply fill procedure
lpDDSSurface->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &fx);
}
//Game Code
//--------------------
//prepare the work surface by filling it with color key color
SurfaceFillColour(G.lpDDSFrontEndOptionsWorkSurface, 55, 7, 7);
etc etc
Yes..i am still using direct x 7 but will be upgrading to dx9. But i think the issue is with the bitshifting for 16bit as it works fine for 32bit.
Anyone spot any obvious mistakes???