Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8427631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:49:54+00:00 2026-06-10T04:49:54+00:00

My problem is that I’m trying to get two different RenderTarget2Ds drawn to the

  • 0

My problem is that I’m trying to get two different RenderTarget2Ds drawn to the screen, but only the last-drawn one is shown. The code is similar to the following, and gets called twice, once by each instance of a class that needs to be drawn with the Draw method:

public override void Draw()
{
  gfxDevice.SetRenderTarget(myRenderTarget);
  gfxDevice.Clear(Thistle);

  //pseudocode
  foreach (something in a list)
  { spritebatch.begin();
    spritebatch.DrawString(something);
    spritebatch.end();
  }

  //reset to the backbuffer 
  gfxDevice.SetRenderTarget(null);
  gfxDevice.Clear(backgroundColor)  //Here is what I thought the offending line was


  //draw the RenderTarget to backbuffer
  spriteBatch.Begin();
  spriteBatch.Draw(myRenderTarget, rect, this.backgroundColor);
  spriteBatch.End();

What I thought would be the solution is to stop clearing the graphicsDevice each time the Draw() method gets called, but if I don’t, everything but the freshly drawn rendertarget gets drawn an ugly purple. Like this: enter image description here

The purple results from End()ing the spritebatch, I think, thanks to this question

What do I need to change in order for both RenderTargets get drawn properly, meaning both widgets get drawn, along with the proper Color.Thistle background?

Ideally, the screen would look like a combination of both: this and this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:49:56+00:00Added an answer on June 10, 2026 at 4:49 am

    You’re correct that you need to remove the gfxDevice.Clear(backgroundColor) call. If you draw to the backbuffer, and then clear the backbuffer, then obviously anything you drew before clearing isn’t going to show up!

    You want to clear the backbuffer before rendering anything, i.e. at the beginning of the frame.

    EDIT

    After taking a more thorough look at the source code provided, I think I know what’s actually going on here–it’s one of the tricky things about using render targets.

    The weird purple you’re seeing is not, in fact, caused by SpriteBatch.End(). That’s the color that render targets are automatically cleared to when XNA resets their memory.

    When does XNA clear out a render target’s memory? Whenever that render target is set onto the graphics device as an active target. So whenever you call SetRenderTarget(null), XNA is obliterating the backbuffer’s memory and resetting it to that lovely purple.

    To avoid this, you need to draw all of your render targets before drawing anything to the backbuffer. Then, set the backbuffer as your active render target, and draw all of the render targets you updated previously in a single pass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem that I am trying to solve. I have two folders
Seems to be a problem that many people have, but all the answers I
I'm having a problem that only seems to happen on my Lenovo Thinkpad Tablet
I have a problem that I have been trying to find a solution for
XML problem that's got me stumped, but is probably very simple... The XML is
This is a design problem that I am trying to figure out. I will
One problem that I have frequently run into lately is the problem of my
The problem that I am having is that I am trying to embed an
I have problem that str_replace can't replace the second to last word... first word
One problem that I come across regularly and yet don't have a solution to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.