代码之家  ›  专栏  ›  技术社区  ›  Neil Knight

ResolveTexture2d-XNA 4中的噩梦

  •  0
  • Neil Knight  · 技术社区  · 14 年前

    我有以下声明:

    ResolveTexture2D rightTex;
    

    我把它用在 Draw 方法如下:

    GraphicsDevice.ResolveBackBuffer(rightTex);
    

    现在,我用 SpriteBatch :

    spriteBatch.Draw(rightTex, new Rectangle(0, 0, 800, 600), Color.Cyan);
    

    这在XNA 3.1中非常有效。但是,现在我要转换到XNA 4, ResolveTexture2D 以及 ResolveBackBuffer 方法已被删除。为了在XNA 4.0中工作,我如何重新编码?

    编辑

    所以,这里还有一些代码可以帮助您。在这里,我初始化renderTargets:

    PresentationParameters pp = GraphicsDevice.PresentationParameters;
    leftTex = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, pp.BackBufferFormat, pp.DepthStencilFormat);
    rightTex = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, pp.BackBufferFormat, pp.DepthStencilFormat);
    

    然后,在我的 方法:

    GraphicsDevice.Clear(Color.Gray);
    rightCam.render(model, Matrix.CreateScale(0.1f), modelAbsTrans);
    GraphicsDevice.SetRenderTarget(rightTex);
    GraphicsDevice.SetRenderTarget(null);
    
    GraphicsDevice.Clear(Color.Gray);
    leftCam.render(model, Matrix.CreateScale(0.1f), modelAbsTrans);
    GraphicsDevice.SetRenderTarget(leftTex);
    GraphicsDevice.SetRenderTarget(null);
    
    GraphicsDevice.Clear(Color.Black);
    
    //start the SpriteBatch with Additive Blend Mode
    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
        spriteBatch.Draw(rightTex, new Rectangle(0, 0, 800, 600), Color.Cyan);
        spriteBatch.Draw(leftTex, new Rectangle(0, 0, 800, 600), Color.Red);
    spriteBatch.End();
    
    2 回复  |  直到 14 年前
        1
  •  3
  •   Barrie Reader    14 年前

        2
  •  6
  •   Andrew Russell    14 年前

    ResolveTexture2D explained here

    RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice, width, height);
    

    graphicsDevice.SetRenderTarget(renderTarget);
    

    graphicsDevice.SetRenderTarget(null);
    

    spriteBatch.Draw(renderTarget, new Rectangle(0, 0, 800, 600), Color.Cyan);
    

    overview of RenderTarget changes in XNA 4.0