我有以下声明:
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);
然后,在我的Draw
方法中,我这样做:
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();