ResolveTexture2D - XNA 4 中的噩梦
我有以下声明:
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();
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 XNA 4.0 中删除
ResolveTexture2D
是 此处解释。基本上你应该使用渲染目标。该过程的要点如下:
创建要使用的渲染目标。
然后将其设置到设备上:
然后渲染场景。
然后取消设置渲染目标:
最后,您可以使用 RenderTarget2D 作为纹理 2D,如下所示:
您还可以找到此 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.
Then set it onto the device:
Then render your scene.
Then un-set the render target:
Finally, you can use a RenderTarget2D as a Texture2D, like so:
You may also find this overview of RenderTarget changes in XNA 4.0 worth reading.
啊哈,给你:
将 GraphicsDevice.SetRenderTarget() 移到 GraphicsDevice.Clear() 调用之前
ahhh, here you go:
Move the GraphicsDevice.SetRenderTarget() before the GraphicsDevice.Clear() call