If anything highlights what I am trying to achieve, please let me know as I am unfimiliar with the functions processed with all this code. I am sorry and hate to just pile stuff on everyone but I am sure an experienced coder can just schim through without even reading to recognize when pixels are being removed or replaced that would most likely be removing a background color around an object within a sprite.
This is where all the bitmap image data is read:
IDirectDrawSurface7 * CSprite::_pMakeSpriteSurface()
{
IDirectDrawSurface7 * pdds4;
HDC hDC;
WORD * wp;
m_bOnCriticalSection = TRUE;
if( m_stBrush == NULL ) return NULL;
CMyDib mydib(m_cPakFileName, m_dwBitmapFileStartLoc); // Reads bitmap data/info
m_wBitmapSizeX = mydib.m_wWidthX; // image width
m_wBitmapSizeY = mydib.m_wHeightY; // image height
pdds4 = m_pDDraw->pCreateOffScreenSurface(m_wBitmapSizeX, m_wBitmapSizeY);
if (pdds4 == NULL) return NULL;
pdds4->GetDC(&hDC);
mydib.PaintImage(hDC);
pdds4->ReleaseDC(hDC);
DDSURFACEDESC2 ddsd;
ddsd.dwSize = 124;
if (pdds4->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) return NULL;
pdds4->Unlock(NULL);
wp = (WORD *)ddsd.lpSurface;
m_wColorKey = *wp;
m_bOnCriticalSection = FALSE;
return pdds4;
}
This is where the Off Screen Surface is created:
IDirectDrawSurface7 * DXC_ddraw::pCreateOffScreenSurface(WORD wSzX, WORD wSzY)
{
DDSURFACEDESC2 ddsd;
IDirectDrawSurface7 * pdds4;
ZeroMemory(&ddsd, sizeof(ddsd));
if ((wSzX % 4) != 0) wSzX += 4 - (wSzX % 4);
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = (DWORD)wSzX;
ddsd.dwHeight = (DWORD)wSzY;
if (m_lpDD4->CreateSurface(&ddsd, &pdds4, NULL) != DD_OK) return NULL;
return pdds4;
}
Before the sprite(surface) is rendered, this is called:
bool CSprite::_iOpenSprite()
{
if (m_lpSurface != NULL) return FALSE;
m_lpSurface = _pMakeSpriteSurface(); // image data read and surface created
if (m_lpSurface == NULL) return FALSE;
m_pDDraw->iSetColorKey(m_lpSurface, m_wColorKey);
m_bIsSurfaceEmpty = FALSE;
DDSURFACEDESC2 ddsd;
ddsd.dwSize = 124;
if (m_lpSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) return FALSE;
m_pSurfaceAddr = (WORD *)ddsd.lpSurface;
m_sPitch = (short)ddsd.lPitch >> 1;
m_lpSurface->Unlock(NULL);
return TRUE;
}
HRESULT DXC_ddraw::iSetColorKey(IDirectDrawSurface7 * pdds4, WORD wColorKey)
{
DDCOLORKEY ddck;
ddck.dwColorSpaceLowValue = _dwColorMatch(pdds4, wColorKey);
ddck.dwColorSpaceHighValue = ddck.dwColorSpaceLowValue;
return pdds4->SetColorKey(DDCKEY_SRCBLT, &ddck);
}
DWORD DXC_ddraw::_dwColorMatch(IDirectDrawSurface7 * pdds4, WORD wColorKey)
{
DWORD dw = CLR_INVALID, * dwp;
DDSURFACEDESC2 ddsd2;
HRESULT hres;
ddsd2.dwSize = sizeof(ddsd2);
while ((hres = pdds4->Lock(NULL, &ddsd2, 0, NULL)) == DDERR_WASSTILLDRAWING);
if (hres == DD_OK)
{
dwp = (DWORD *)ddsd2.lpSurface;
*dwp = (DWORD)wColorKey;
dw = *(DWORD *)ddsd2.lpSurface;
dw &= (1 << ddsd2.ddpfPixelFormat.dwRGBBitCount)-1;
pdds4->Unlock(NULL);
}
return dw;
}
This renders the sprite in the end:
m_pDDraw->m_lpBackB4->BltFast( dX, dY, m_lpSurface, &rcRect, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT );
Thanks for your patience and support.