我有以下声明:
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();
答案 0 :(得分:6)
从XNA 4.0中删除ResolveTexture2D
为explained here。
基本上你应该使用渲染目标。这个过程的要点是这样的:
创建要使用的渲染目标。
RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice, width, height);
然后将其设置到设备上:
graphicsDevice.SetRenderTarget(renderTarget);
然后渲染你的场景。
然后取消设置渲染目标:
graphicsDevice.SetRenderTarget(null);
最后,您可以使用RenderTarget2D作为Texture2D,如下所示:
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, 800, 600), Color.Cyan);
您可能还会发现此overview of RenderTarget changes in XNA 4.0值得一读。
答案 1 :(得分:3)