After Writing to a RenderTarget, How to Efficiently Clone the Output?

前端 未结 3 1971
陌清茗
陌清茗 2021-01-17 23:46

XNA noob here, learning every day. I just worked out how to composite multiple textures into one using a RenderTarget2D. However, while I can use the RenderTarget2D as a Te

3条回答
  •  北海茫月
    2021-01-18 00:08

    if you are having problems with your rendertarget being dynamically resized when drawing it somewhere else, you could just have an off-screen rendertarget with a set size that you copy your finished RT to like this:

    Rendertarget2D offscreenRT = new RenderTarget2D(_device, width, height);
    _device.SetRenderTarget(offscreenRT);
    _device.Clear(Color.Transparent);
    
    SpriteBatch  spriteBatch = new SpriteBatch(_device);
    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
    spriteBatch.Draw(buffer, Vector2.Zero, Color.White);
    spriteBatch.End();
    _device.SetRenderTarget(null);
    

提交回复
热议问题