XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Render To Texture Depth Problems

Last post 05-09-2008 11:01 AM by Jeromy Stroh. 1 replies.
  • 05-09-2008 2:09 AM

    Render To Texture Depth Problems

    I'm rendering my entire scene to a 2d texture but the depth info isn't being used.

    When I render normally to the backbuffer the depth information is used.

    Here's what I'm doing:

    // Cache the current depth buffer

    DepthStencilBuffer old = GraphicsDevice.DepthStencilBuffer;

    // render to the "backbuffer"

    GraphicsDevice.SetRenderTarget(0, backBuffer);

    // kill everything

    graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

    // Set our custom depth buffer

    GraphicsDevice.DepthStencilBuffer = backDepthStencilBuffer;

     

    // draw everything

    base.Draw(gameTime);

     

    // Set render target back to the real back buffer

    GraphicsDevice.SetRenderTarget(0, null);

     

    // Reset the depth buffer

    GraphicsDevice.DepthStencilBuffer = old;

    // and render the "back buffer" to the back buffer

    Rectangle rect = new Rectangle(0,0,

    GraphicsDevice.PresentationParameters.BackBufferWidth,

    GraphicsDevice.PresentationParameters.BackBufferHeight);

    backBufferSpriteBatch.Begin(SpriteBlendMode.None);

    backBufferSpriteBatch.Draw(backBuffer.GetTexture(), rect, Color.White);

    backBufferSpriteBatch.End();

     

    I first tried it without creating a whole new depth buffer and it didn't work and then created a depth buffer and it still doesn't work :(

     

    Halp! ;o

     

    EDIT:

     

    Here's the loading code:

    // load the backbuffer

    backBuffer = new RenderTarget2D(

    GraphicsDevice, // the rendering device

    GraphicsDevice.PresentationParameters.BackBufferWidth, // screen width

    GraphicsDevice.PresentationParameters.BackBufferHeight, // screen height

    1, // 1 mipmap level

    GraphicsDevice.DisplayMode.Format, // bgr32

    0, // no multisample (AA)

    0 // no multisample (AA)

    );

    // load the depth for the back buffer

    backDepthStencilBuffer = new DepthStencilBuffer(

    GraphicsDevice, // rendering device

    GraphicsDevice.PresentationParameters.BackBufferWidth, // screen width

    GraphicsDevice.PresentationParameters.BackBufferHeight, // screen height

    GraphicsDevice.DepthStencilBuffer.Format, // format of actual bb

    0, // no multisample (AA)

    0 // no multisample (AA)

    );

    // load the spritepatch used to display the backbuffer

    backBufferSpriteBatch = new SpriteBatch(GraphicsDevice);

  • 05-09-2008 11:01 AM In reply to

    Re: Render To Texture Depth Problems

    Silly spritebatch was messing with my render states and not resetting them:

    backBufferSpriteBatch.Begin(SpriteBlendMode.None);

     

    Ah well, found some neat effects in the process so no loss ;o

Page 1 of 1 (2 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG