Hello everyone... Just browsing through here because i LOVE the idea, teej
wish this was around when i first met DDraw!
thought i might throw in some code for determining the pixels in 16bit mode.
during initialization, call:
ZeroMemory(&ddPF, sizeof(ddPF));
ddPF.dwSize = sizeof(ddPF);
// get the information from the back surface
ddret = lpSurface->GetPixelFormat(&ddPF);
if (ddret != DD_OK)
return FALSE;
// now we interpret the return values
if (ddPF.dwFlags & DDPF_RGB) {
switch (ddPF.dwRGBBitCount) {
case 16: {
DWORD dwRBM = ddPF.dwRBitMask;
DWORD dwGBM = ddPF.dwGBitMask;
DWORD dwBBM = ddPF.dwBBitMask;
// calculate shift left amount
for (iRSHL=0; (dwRBM&1)!=1; iRSHL++) dwRBM>>=1;
for (iGSHL=0; (dwGBM&1)!=1; iGSHL++) dwGBM>>=1;
for (iBSHL=0; (dwBBM&1)!=1; iBSHL++) dwBBM>>=1;
// calculate shift right amount
for (iRSHR=8; (dwRBM&1)==1; iRSHR--) dwRBM>>=1;
for (iGSHR=8; (dwGBM&1)==1; iGSHR--) dwGBM>>=1;
for (iBSHR=8; (dwBBM&1)==1; iBSHR--) dwBBM>>=1;
// calculate the mask to use for merging colors
// merge means taking the average of two pixels, giving a 'translucent' effect
dwMergeMask = 0xFFFFFFFF;
if (iRSHL>0)
dwMergeMask ^= 1<<(iRSHL+15) | 1<<(iRSHL-1);
if (iGSHL>0)
dwMergeMask ^= 1<<(iGSHL+15) | 1<<(iGSHL-1);
if (iBSHL>0)
dwMergeMask ^= 1<<(iBSHL+15) | 1<<(iBSHL-1);
dwMergeMask ^= 1<<31 | 1<<15;
break;
}
(that was a quick cut and paste, so there is probably braces missing)
then, when you want to write the pixel, use:
buffer[offset]= (red >>iRSHR<<iRSHL) | (green >>iGSHR<<iGSHL) | (blue >>iBSHR<<iBSHL);
this way, red green and blue are values from 0 to 255 and it will always work, whether 5-5-5 or 5-6-5 or whatever format.
erm... i don't want to intrude on what teej is telling you so just ignore the dwMergeMask for the moment
Edited by - zenic on May 10, 2001 1:27:49 AM