Here in the attached code strechrect method is getting failed and its returning the -ve value. I am doing operations as below. please give me what wrong i am doing here.
1. Getting the offscreenplain surface using CreateOffscreenPlainSurface method.
2. modifying the plain surface.
3. Getting the back buffer of the surface
4. Putting back plain surface to the back buffer using strechrect method.
void CTriangleRenderer::LockSurfaceExtra()
{
DWORD bkColor;
D3DCOLOR Color;
HDC hdc;
HRESULT hr;
D3DLOCKED_RECT lockedRect;
DWORD *pMem, colorVal;
RECT rc, wrc, mrc,destRect;
int i, j, k, m, linemin, linemax, linecnt, linesDrawn = 0,pitch;
IDirect3DSurface9* backbuffer = NULL;
D3DSURFACE_DESC d3dsd;
if( NULL == m_pd3dDevice )
return;
g_increase=g_increase+5;
m_pd3dDevice->GetBackBuffer( 0,
0,
D3DBACKBUFFER_TYPE_MONO,
&backbuffer );
m_pd3dDevice->CreateOffscreenPlainSurface(1400,
1100,
D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT,
&m_pd3dRTSBackup,
NULL);
if (m_pd3dRTSBackup != NULL)
{
hr = m_pd3dRTSBackup->LockRect(&lockedRect, NULL, 0);
if (SUCCEEDED(hr))
{
pitch = lockedRect.Pitch / sizeof(DWORD);
pMem = (DWORD *)lockedRect.pBits;
}
GetClientRect(m_hwnd,&rc);
m_pd3dRTSBackup->GetDesc(&d3dsd);
for (WORD y = 0; y <d3dsd.Height ; ++y)
{
for (WORD x = 0; x < d3dsd.Width; ++x)
{
pMem[(pitch*y)+x] = D3DCOLOR_ARGB(255, 0,0,0);
}
}
m_pd3dRTSBackup->UnlockRect();
}
m_pd3dDevice->BeginScene();
hr=m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
hr= m_pd3dDevice->StretchRect(m_pd3dRTSBackup,
NULL,
backbuffer,
NULL,
D3DTEXF_NONE );
backbuffer->Release();
m_pd3dDevice->EndScene();
m_pd3dDevice->Present ( NULL, NULL, NULL, NULL );
}