views:

430

answers:

3

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

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

Goz
I'm using a book, Game Programming all in one, and it is old enough to use DirectX 8. The author is demonstrating surfaces, so i'm just using the code he's given.
tiddlydum
Ahh, right, StretchRect is returning FAILED.
tiddlydum
well get the DirectX debug runtime going and it will most likely tell you EXACTLY why its failing. To do so go to Start->Programs->DirectX SDK->DX Utilities->DX control panel and select the debug runtime under D3D.
Goz
+1  A: 

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.

gatorfax
From the SDK: "Stretching is not supported if the destination surface is an off-screen plain surface but the source is not"
gatorfax
A: 

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.

legalize