Sign in to follow this  
barp12

how to use StretchRect?

Recommended Posts

how to use StretchRect function to save the back buffer to render target?(Direct3D9) [Edited by - barp12 on August 12, 2007 8:23:46 AM]

Share this post


Link to post
Share on other sites
Are you sure you want to copy from a backbuffer to a render target? Why not just render your image to the render target in the first place? [smile]

Have you consulted the SDK documentation for using StretchRect() - it's a pretty simple function with the only complication being which pool and resource types you can copy to/from...

hth
Jack

Share this post


Link to post
Share on other sites
I do this kind of thing a lot, normally for post-processing effects, where you dont want to re-render the whole scene to a new target, and you dont want to use use the backbuffer as a texture in an effect.. (because backbuffer is large and non-square).

Basically, just make sure your new texture is a render-target, with D3DPOOl_DEFAULT

Then just do the stretch rect function, set the rect to NULL ...

Share this post


Link to post
Share on other sites
what with the another parameters?
does it save the back buffer alpha channnel?

[Edited by - barp12 on August 14, 2007 6:18:39 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by barp12
what with the another parameters?
does it save the back buffer alpha channnel?


The call would probably look something like this:

pd3dDevice->StretchRect( pSourceSurface, NULL, pDestSurface, NULL, D3DTEXF_LINEAR);

If you copy the backbuffer to a surface which is created with an alpha channel you get that one filled as well.

Share this post


Link to post
Share on other sites
i dont get the alpha channel
i create the texture like this

HR(D3DXCreateTexture(gd3dDevice,800,600,0,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&backBuffer));
HR(backBuffer->GetSurfaceLevel(0,&backBufferSucrface));

backBuffer is the render target
And Get The BackBuffer Like This


IDirect3DSurface9* backBufferCurrect;
HR(gd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_LEFT,&backBufferCurrect));
HR(gd3dDevice->StretchRect(backBufferCurrect,0,backBufferSucrface,0,D3DTEXF_LINEAR));
ReleaseCOM(backBufferCurrect);

what worng?

Share this post


Link to post
Share on other sites
Quote:
Original post by barp12
i dont get the alpha channel
i create the texture like this

HR(D3DXCreateTexture(gd3dDevice,800,600,0,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&backBuffer));
HR(backBuffer->GetSurfaceLevel(0,&backBufferSucrface));

backBuffer is the render target
And Get The BackBuffer Like This


IDirect3DSurface9* backBufferCurrect;
HR(gd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_LEFT,&backBufferCurrect));
HR(gd3dDevice->StretchRect(backBufferCurrect,0,backBufferSucrface,0,D3DTEXF_LINEAR));
ReleaseCOM(backBufferCurrect);

what worng?


I have got problems with the alpha channel when the backbuffer was of format D3DFMT_X8R8G8B8. If you are creating an application with the SDK template you could try to switch with Change device F2.

Share this post


Link to post
Share on other sites
thx but i solved it the back buffer format wan't had alpha channel so i modify the format to A8R8G8B8
and it works

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this