0

我有以下声明:

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();
4

2 回答 2

6

此处解释ResolveTexture2D了从 XNA 4.0 中删除的内容。

基本上你应该使用渲染目标。该过程的要点如下:

创建要使用的渲染目标。

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);

您还可能会发现这篇关于 XNA 4.0 中 RenderTarget 更改的概述值得一读。

于 2010-11-09T12:53:23.167 回答
3

啊哈,给你:在 GraphicsDevice.Clear() 调用之前移动 GraphicsDevice.SetRenderTarget()

于 2010-11-09T16:28:40.387 回答