ResolveTexture2D - XNA 4 中的噩梦

发布于 2024-10-01 00:10:09 字数 1659 浏览 5 评论 0原文

我有以下声明:

ResolveTexture2D rightTex;

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

GraphicsDevice.ResolveBackBuffer(rightTex);

现在,我使用 SpriteBatch 将其绘制出来:

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

这在 XNA 3.1 中效果非常好。但是,现在我正在转换为 XNA 4,ResolveTexture2DResolveBackBuffer 方法已被删除。我该如何重新编码才能在 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();

I have the following declaration:

ResolveTexture2D rightTex;

And I use it in the Draw method like so:

GraphicsDevice.ResolveBackBuffer(rightTex);

Now, I then draw it out using the SpriteBatch:

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

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?

EDIT

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情旳空白 2024-10-08 00:10:09

从 XNA 4.0 中删除 ResolveTexture2D此处解释

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

创建要使用的渲染目标。

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

您还可以找到此 XNA 4.0 中 RenderTarget 更改的概述值得一读。

The removal of ResolveTexture2D from XNA 4.0 is explained here.

Basically you should use render targets. The gist of the process goes like this:

Create a render target to use.

RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice, width, height);

Then set it onto the device:

graphicsDevice.SetRenderTarget(renderTarget);

Then render your scene.

Then un-set the render target:

graphicsDevice.SetRenderTarget(null);

Finally, you can use a RenderTarget2D as a Texture2D, like so:

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

You may also find this overview of RenderTarget changes in XNA 4.0 worth reading.

乖乖哒 2024-10-08 00:10:09

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文