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, new Rectangle(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.



Answer this question

render a copy of the backbuffer

  • ti_m

    You need to grab the backbuffer and keep a reference to it before replacing it, and then restore it at the end.

  • DAEscola

    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);



  • uhhuh

    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.

  • mary jane

    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


  • GusBraga

    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.


  • Steven P.

    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.


  • render a copy of the backbuffer