ResolveTexture2D-XNA 4中的噩梦

ResolveTexture2D-XNA 4中的噩梦,xna,xna-4.0,Xna,Xna 4.0,我有以下声明: ResolveTexture2D rightTex; 我在Draw方法中使用它,如下所示: GraphicsDevice.ResolveBackBuffer(rightTex); 现在,我用SpriteBatch将其绘制出来: spriteBatch.Draw(rightTex, new Rectangle(0, 0, 800, 600), Color.Cyan); 这在XNA3.1中非常有效。但是,现在我要转换到xna4,ResolveTexture2D和resolveb

我有以下声明:

ResolveTexture2D rightTex;
我在
Draw
方法中使用它,如下所示:

GraphicsDevice.ResolveBackBuffer(rightTex);
现在,我用
SpriteBatch
将其绘制出来:

spriteBatch.Draw(rightTex, new Rectangle(0, 0, 800, 600), Color.Cyan);
这在XNA3.1中非常有效。但是,现在我要转换到xna4,
ResolveTexture2D
resolvebackuffer
方法已被删除。为了在XNA4.0中工作,我将如何对其重新编码

编辑

因此,这里有一些代码可能会有所帮助。在这里,我初始化渲染目标:

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

ResolveTexture2D
从XNA 4.0中删除是不正确的

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

创建要使用的渲染目标

RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice, width, height);
然后将其设置到设备上:

graphicsDevice.SetRenderTarget(renderTarget);
然后渲染场景

然后取消设置渲染目标:

graphicsDevice.SetRenderTarget(null);
最后,可以使用RenderTarget2D作为纹理2D,如下所示:

spriteBatch.Draw(renderTarget, new Rectangle(0, 0, 800, 600), Color.Cyan);
你可能也会发现这本书值得一读。

啊,给你:
在GraphicsDevice.Clear()调用之前移动GraphicsDevice.SetRenderTarget()!刚刚解决了一个透明度问题,但很好:D