ResolveTexture2D - XNA 4 中的噩梦 [英] ResolveTexture2D - The nightmare in XNA 4

查看:21
本文介绍了ResolveTexture2D - XNA 4 中的噩梦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下声明:

ResolveTexture2D rightTex;

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

And I use it in the Draw method like so:

GraphicsDevice.ResolveBackBuffer(rightTex);

现在,我然后使用 SpriteBatch 绘制它:

Now, I then draw it out using the SpriteBatch:

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

这在 XNA 3.1 中效果很好.但是,现在我正在转换为 XNA 4,ResolveTexture2DResolveBackBuffer 方法已被删除.我将如何重新编码以便在 XNA 4.0 中工作?

This works fantastic in XNA 3.1. But, now I'm converting to XNA 4, ResolveTexture2D and the ResolveBackBuffer method have been removed. How would I re-code this in order to work in XNA 4.0?

编辑

所以,这里还有一些代码可能会有所帮助.在这里,我初始化了 RenderTargets:

So, here is some more code to maybe help. Here I initialise the 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 方法中:

Then, in my Draw method I do:

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

推荐答案

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

ahhh, here you go: Move the GraphicsDevice.SetRenderTarget() before the GraphicsDevice.Clear() call

这篇关于ResolveTexture2D - XNA 4 中的噩梦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆