代码之家  ›  专栏  ›  技术社区  ›  jasonh

更改RenderTarget会导致紫色屏幕吗?

  •  5
  • jasonh  · 技术社区  · 14 年前

            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绘制它们),它会导致一个完全紫色的屏幕。我能做些什么来解决这个问题?

    3 回复  |  直到 14 年前
        1
  •  3
  •   jasonh    14 年前

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

        2
  •  2
  •   Michael Aquilina    12 年前

    protected override void Draw(GameTime gameTime)
    {
         GraphicsDevice.SetRenderTarget(_renderTarget);
    
         //...
         //Perform Rendering to the specified target
         //...
    
         GraphicsDevice.SetRenderTarget(null);
    
         GraphicsDevice.Clear(Color.CornflowerBlue);
    
         //...
         //Code that draws to the users screen goes here
         //...
    }
    

    这将防止您按照其他人的建议在Update方法中进行渲染,这在许多方面都是违反直觉的。

        3
  •  1
  •   TankorSmash    12 年前

    什么时候? spritebatch.End() 被称为对象的对象被写入backbuffer,或者在您的情况下被写入backbuffer tempTarget . 为了制造纹理,

    • 改变目标
    • 呼叫开始
    • 打电话给所有的抽签者
    • 结束spritebatch

    推荐文章