Reputation: 507
How do I port DX8's IDirect3DDevie8::CopyRects to DirectX9? I have found a function (stretchRect), but it doesn't seem to work...
//clear the window to blue
m_pD3DDevice->Clear (0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
//get back buffer
LPDIRECT3DSURFACE9 pBackBuffer;
m_pD3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
//start rendering
m_pD3DDevice->BeginScene();
//copy the surface to the screen
m_pD3DDevice->CopyRects (m_pD3DSurface, NULL, 0, pBackBuffer, NULL);
//end rendering
m_pD3DDevice->EndScene();
//present the rendered scene to the screen
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
heres the "replacement" code if it worked...
StretchRect(m_pD3DSurface, NULL, pBackBuffer, NULL, D3DTEXF_NONE);
ran the D3D debugger, here's the output:
Direct3D9: (INFO) :======================= Hal SWVP device selected
Direct3D9: (INFO) :HalDevice Driver Style 9
Direct3D9: :BackBufferCount not specified, considered default 1
Direct3D9: :DoneExclusiveMode
Direct3D9: (INFO) :Failed to create driver indexbuffer
Direct3D9: (INFO) :Using P4 PSGP
Direct3D9: (ERROR) :This format is not supported for offscreen plain surfaces. CreateOffscreenPlainSurface fails.
Game Library.exe has triggered a breakpoint
Direct3D9: (ERROR) :Invalid source surface interface specified. StretchRect fails CreateOffscreenPlainSurface fails.
Upvotes: 1
Views: 3156
Reputation: 2253
What is the format of your back buffer? What is the format of your surface?
The debug runtime you posted above is telling you what's wrong: the surface formats are somehow incompatible.
StretchRect
is for copying between surfaces on the device. UpdateSurface
is for copying from the CPU to the GPU. So you're using the right function, but you've got incompatible arguments somehow. Try taking a look at Chapter 4. 2D Applications from my book The Direct3D Graphics Pipeline. Section 4.9 discusses how to use StretchRect.
Upvotes: 1
Reputation: 1142
I don't think you want to use StretchRect. Have you tried using IDirect3DDevice9::UpdateSurface instead.
MSDN IDirect3DDevice9::UpdateSurface
This method is similar to CopyRects in DirectX 8.
Upvotes: 2
Reputation: 62323
Firstly, do you check what the debug runtime tells you when you try and stretchrect?
Secondly, what HRESULT does it return?
Finally, you would be much better off doing something like this using a texture. It will be many times quicker and isn't particularly difficult to do either ...
Upvotes: 0