Sign in to follow this  
GogoAckman

Make a texture from front or back buffer

Recommended Posts

GogoAckman    122
Hi, I actually works on a port for an emu to xbox but I have a problem, I really don t know anything in direct3d, what I need is to get the frontbuffer from IDirect3DDevice8 *g_pDevice; and to copy it in a new texture (let s call it LPDIRECT3DTEXTURE8 PgTexture; ) I think I must use a D3DLOCKED_RECT Rect; and copy every pixel from backbuffer to the texture, but I really don t know how it works, if someone can help me :) . Hope it is clear enough :D .

Share this post


Link to post
Share on other sites
qazlop    229
why copy the front (or back) buffer to a texture? instead just render to the texture instead of the back buffer. See SetRenderTarget(), as well as search for samples on render to texture. Also if you need to display the scene, either render the texture on a quad to the backbuffer, or rerender the scene depending on which would work better (you dont specify why you need render to a texture).

Share this post


Link to post
Share on other sites
GogoAckman    122
Quote:
Original post by qazlop
why copy the front (or back) buffer to a texture? instead just render to the texture instead of the back buffer. See SetRenderTarget(), as well as search for samples on render to texture. Also if you need to display the scene, either render the texture on a quad to the backbuffer, or rerender the scene depending on which would work better (you dont specify why you need render to a texture).


I need to get it on a texture, to display a little image of the game in the background, I have a render fonction to do that but it needs a texture, that s why :) , hope it is clear enough, or I ll post a screen :) .

Share this post


Link to post
Share on other sites
eFoDay    300

// i dont know if this will work because i havnt tried it
// i made it using info i found on the net

LPDIRECT3DTEXTURE9 createTextureFromRT()
{
LPDIRECT3DSURFACE9 surface;
D3DSURFACE_DESC surfDesc;
LPDIRECT3DTEXTURE9 texture;
LPDIRECT3DSURFACE9 texSurface;

// get the back surface and its description
device->GetRenderTarget(0, &surface);
surface->GetDesc(&surfDesc);

// create a texture the same as the back surface
device->CreateTexture(surfDesc.Width, surfDesc.Height, 0, D3DUSAGE_AUTOGENMIPMAP, surfDesc.Format, D3DPOOL_DEFAULT, &texture, NULL);

// get the textures surface
texture->GetSurfaceLevel(0, &texSurface);

// copy the back surface to the textures surface
D3DXLoadSurfaceFromSurface(texSurface, NULL, NULL, surface, NULL, NULL, D3DX_DEFAULT, 0);

// release both surfaces
texSurface->Release();
surface->Release();

// and your left with a a d3d texture containing the back surface
return texture;
}



edit:
I have tried it now and it doesnt appear to work

edit:
It works now but its showing the image flipped

[Edited by - eFoDay on March 28, 2005 6:34:28 PM]

Share this post


Link to post
Share on other sites
turnpast    1011
To use the back buffer for anything you need to specify D3DPRESENTFLAG_LOCKABLE_BACKBUFFER at device creation -- this will slow things down.

You can copy from one surface to another using D3DXLoadSurfaceFromSurface. Use the SurfaceLevel(0) of your texture as the target.

DX9 and your hardware may support multiple render targets. If this is the case, you can render to the screen and a target at the same time -- there are a lot of restrictions (sizes and such) on use though and it simply may not work for your application. see: SetRenderTarget (as qazlop suggested).

You can also simply render all of your stuff twice, once to the screen and once to a target (your texture).

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