Original Post
I''m having a problem with CopyRects. I have this code (below) which i got from a book (forget which). It works perfectly on my desktop computer running a Geforce3, however, on my laptop with a S3 Twister K it doesn''t seem to work for 640x480 mode, but works for 800x600 mode. After debugging the program i''ve tracked the problem down to the following call.
hr = g_lpD3DDevice->CopyRects(pSurface, pSrcRect, 1,pTexSurface, &destPoint);
which is returning an INVALIDCALL when i call it in 640x480 mode. the format for the screen is 16-bit R5G6B5 and the bitmap is 800x600 big in 32-bit X8R8G8B8 mode.
any help is appreciated.
thanks.
//-----------------------------------------------------------------------------
void CreateTextureFromSurface(LPDIRECT3DDEVICE8 g_lpD3DDevice,LPDIRECT3DSURFACE8 pSurface, RECT* pSrcRect,
LPDIRECT3DTEXTURE8* ppTexture)
{
HRESULT hr = 0;
int width = pSrcRect->right - pSrcRect->left;
int height = pSrcRect->bottom - pSrcRect->top;
D3DSURFACE_DESC surfDesc;
pSurface->GetDesc(&surfDesc);
hr = D3DXCreateTexture(g_lpD3DDevice, width, height,1, 0, surfDesc.Format, D3DPOOL_DEFAULT, ppTexture);
// Retrieve the surface image of the texture.
LPDIRECT3DSURFACE8 pTexSurface;
LPDIRECT3DTEXTURE8 pTexture = *ppTexture;
pTexture->GetLevelDesc(0, &surfDesc);
pTexture->GetSurfaceLevel(0, &pTexSurface);
// Create a clean surface to clear the texture with.
LPDIRECT3DSURFACE8 pCleanSurface;
D3DLOCKED_RECT lockRect;
hr = g_lpD3DDevice->CreateImageSurface(surfDesc.Width, surfDesc.Height, surfDesc.Format, &pCleanSurface);
hr = pCleanSurface->LockRect(&lockRect, NULL, 0);
memset((BYTE*)lockRect.pBits, 0, surfDesc.Height * lockRect.Pitch);
hr = pCleanSurface->UnlockRect();
hr = g_lpD3DDevice->CopyRects(pCleanSurface, NULL, 0,pTexSurface, NULL);
pCleanSurface->Release();
// Copy the image to the texture.
POINT destPoint = { 0, 0 };
hr = g_lpD3DDevice->CopyRects(pSurface, pSrcRect, 1, pTexSurface, &destPoint);
pTexSurface->Release();
}