在紫色屏幕中更改 RenderTarget 结果? [英] Changing RenderTarget Results in Purple Screen?

查看:18
本文介绍了在紫色屏幕中更改 RenderTarget 结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行时更改 RenderTargets,因此我可以在运行时绘制一些元素,操作它们,然后最终将纹理绘制到屏幕上.问题是,如果我在运行时更改 RenderTarget,屏幕会变成紫色.这是我在 Draw 中得到的代码:

I'm attempting to change RenderTargets at runtime, so I can draw some elements at runtime, manipulate them and then finally draw the texture to the screen. Problem is, the screen turns purple if I change the RenderTarget at runtime. Here's the code I've got in Draw:

        RenderTarget2D tempTarget = new RenderTarget2D(GraphicsDevice, 128, 128, 1,
            GraphicsDevice.DisplayMode.Format, GraphicsDevice.PresentationParameters.MultiSampleType,
            GraphicsDevice.PresentationParameters.MultiSampleQuality, RenderTargetUsage.PreserveContents);

        GraphicsDevice.SetRenderTarget(0, tempTarget);
        GraphicsDevice.Clear(ClearOptions.Target, Color.SpringGreen, 0, 0);
        GraphicsDevice.SetRenderTarget(0, null);

我如何创建 RenderTarget 似乎并不重要,如果我在运行时创建(并且我确实需要在运行时创建内存中的纹理并使用 SpriteBatch 在它们上绘制)它会导致一个完全紫色的屏幕.我该怎么做才能解决这个问题?

It doesn't seem to matter how I create the RenderTarget, if I do it at runtime (and I do need to create in-memory textures at runtime and draw on them with SpriteBatch) it results in an entirely purple screen. What can I do to fix this?

推荐答案

看起来最好的选择是在 Draw 以外的地方创建 RenderTarget,在更新期间绘制到它,保存生成的纹理(并根据需要进行操作)然后在 Draw 期间绘制该纹理.

It looks like the best option is to create the RenderTarget somewhere other than Draw, draw to it during Update, save the resulting texture (and manipulate as necessary) then draw that texture during Draw.

这篇关于在紫色屏幕中更改 RenderTarget 结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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