Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#Actualkamal7

Posted 30 July 2012 - 09:55 PM

Here is some code that I promised (I am not sure if this will achieve what I want, I tried to show all the highlights from the old source code that I am converting to Direct X 9... hopefully I got the right stuff):

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.

#4kamal7

Posted 30 July 2012 - 09:53 PM

Here is some code that I promised (I am not sure if this will achieve what I want, I tried to show all the highlights from the old source code that I am converting to Direct X 9... hopefully I got the right stuff):

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();
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.

#3kamal7

Posted 30 July 2012 - 09:46 PM

Here is some code that I promised (I am not sure if this will achieve what I want, I tried to show all the highlights from the old source code that I am converting to Direct X 9... hopefully I got the right stuff):

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 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();
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;
}

Here is some more code that is handled before the sprite(surface) is rendered:
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;
}



Thanks for your patience and support.

#2kamal7

Posted 30 July 2012 - 09:43 PM

Here is some code that I promised (I am not sure if this will achieve what I want, I tried to show all the highlights from the old source code that I am converting to Direct X 9... hopefully I got the right stuff):

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();
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;
}

Here is some more code that is handled before the sprite(surface) is rendered:
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;
}


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 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.

Thanks for your patience and support.

#1kamal7

Posted 30 July 2012 - 09:42 PM

Here is some code that I promised (I am not sure if this will achieve what I want, I tried to take out all the highlights from the old source code... hopefully I got the right stuff):

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();
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;
}

Here is some more code that is handled before the sprite(surface) is rendered:
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;
}


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 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.

Thanks for your patience and support.

PARTNERS