render a copy of the backbuffer

Hello I have read several posts about that, but nothing seems to work for me,

I try to save my backbuffer (to store it in a surface)

then I would like to draw this saved surface...

so, I need two things.

1: save my backbuffer

MyBackBufferSurface=graphics.GraphicsDevice.GetBackBuffer(0,0);

2:render my backBuffer

spriteRenderer.Draw(MyBackBufferTexture,newRectangle(0, 0, 512, 512),Color.White);

I used :MyBackBufferSurface= MyBackBuffertexture.GetSurfaceLevel(0); to assosiate my surface with my texture

I end up with a black surface when I render my texutre

please help me I on this since a week and it makes me crazy.

[1051 byte] By [kosinus] at [2007-12-24]
# 1
Similar question was asked in the other forum. You need to create a "RenderTarget" texture yourself, and set its top surface as the render target.

Create the texture with:
ResourceUsage = ResourceUsage.RenderTarget
SurfaceFormat = myGraphicsComponent.BackBufferFormat
ResourcePool = ResourcePool.Default

Get the top surface with texture.GetSurfaceLevel(0)

Set that as the rendertarget with graphicsDevice.SetRenderTarget(0, surface);

Render, and then restore your original backbuffer.

KrisNye at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 2

thanx it seems to work better, but i end up with a frozen display because I dont know how to get back the original backbuffer at the end.

is it the getbackbuffer funciton ?

kosinus at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 3
You need to grab the backbuffer and keep a reference to it before replacing it, and then restore it at the end.
KrisNye at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 4

Surface oldRenderTarget = device.GetRenderTarget(0);

Surface myTargetSurface = myTargetTexture.GetSurfaceLevel(0);

using (myTargetSurface)

{

device.SetRenderTarget(0, myTargetSurface);

device.Clear(Color.Color); //you may also want to clear depth here

//Render whatever you want to your texture

}

device.SetRenderTarget(0, oldRenderTarget);

X-Tatic at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 5

thanx a lot

i appreciate your help

it seems to work better...

but not ok yet, I m now with a red flickering screen ( seems to be some kind of system memory...)

i m drawing my target texture with a spritebatch, is that ok ?

I did exactly what you told me. I m not sure where it doesnt work.

kosinus at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 6

This approach have some disadvantages:

1. No hardware anti-aliasing.

2. Need full-resolution render target.

3. Need full-resolution copy from RT to backbuffer.

Better use following approach.

1. Render scene to backbuffer.

2. Stretch backbuffer to RT texture:

device.StretchRectangle(backbuffer_surface, null, texture_surface, null, Microsoft.Xna.Framework.Graphics.TextureFilter.Linear);

I've got this methods from Game Developers conference's publication "Special Effects in Direct3D" by Greg James (nVidia corp.)

P.S. Sorry for my english, i am russian.

U-Way at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...