Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got this simple code that uses SpriteBatch to draw a texture onto a RenderTarget2D:

private void drawScene(GameTime g)
    effect.Fog = true;
    GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
    SceneTexture = targetScene;

private void drawPostProcessing(GameTime g)
    effect.SceneTexture = SceneTexture;
    spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, null, null, null);
        if (Bloom) effect.BlurEffect.CurrentTechnique.Passes[0].Apply();
            new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height),
    BloomTexture = targetBloom;

Both methods are called from my Draw(GameTime gameTime) function. First drawScene is called, then drawPostProcessing is called.

The thing is, when I run this code I get an error on the spriteBatch.Draw call:

The render target must not be set on the device when it is used as a texture.

I already found the solution, which is to draw the actual render target (targetScene) to the texture so it doesn't create a reference to the loaded render target.

However, to my knowledge, the only way of doing this is to write:

SpriteBatch.Draw(inputTarget, ...)

Which encounters the same exact problem I'm having right now.

So, the question I'm asking is: how would I render inputTarget to outputTarget without reference issues?

share|improve this question
up vote 0 down vote accepted

Sounds like targetScene and targetBloom are the same texture. You should check you're not assigning one to the other somewhere in your code. Or maybe, your spriteBatch is using the same texture you're using as a render target (targetBloom); you just can't do that (that's a hardware limitation).

I know your question is about how to fix your fix, but I don't understand what you're trying to do, and I see no reason why your first solution wouldn't work.

share|improve this answer
OH, just as I read that everything just clicked into understanding. Yeah, targetScene and targetBloom were the same. I was initializing them via: targetScene = targetBloom = new RenderTarget2D(...) – Jared Apr 4 '12 at 18:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.