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 7709363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:50:34+00:00 2026-06-01T00:50:34+00:00

All I want is to clear my renderTarget2D once so that it starts off

  • 0

All I want is to clear my renderTarget2D once so that it starts off compeltely transparent, and then preserve it’s contents between frames.

I draw the renderTarget texture after I draw the background texture, so I don’t want it to paint over. However Clear(Color.Transparent) it shows up as an opaque purple, which as I understand is the default clear color…

What am I doing wrong? I tried changing the SurfaceFormat parameter in the constructor but that had no effect. what am I doing wrong?

// instantiate renderTarget to preserve contents
renderTarget = new RenderTarget2D(GraphicsDevice,
                                   GraphicsDevice.PresentationParameters.BackBufferWidth,
                                   GraphicsDevice.PresentationParameters.BackBufferHeight,
                                   false,
                                   GraphicsDevice.PresentationParameters.BackBufferFormat,
                                   DepthFormat.Depth24,
                                   0,
                                   RenderTargetUsage.PreserveContents);
// clear with transparent color
GraphicsDevice.SetRenderTarget(Globals.renderTarget);
GraphicsDevice.Clear(Color.Transparent);
GraphicsDevice.SetRenderTarget(null);
  • 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-01T00:50:36+00:00Added an answer on June 1, 2026 at 12:50 am

    RenderTarget2D is used to draw things off screen which brings up the fact that your code sample is drawing nothing to the screen. Use the sprite batch to actually draw the RenderTarget2D to the back buffer which will effect the display.

    Another problem being that by drawing a fully transparent RenderTarget2D is you are not going to change anything on screen so even if you code was working creating a rendertarget, clearing it with transparency, and drawing it effects nothing on the screen.

    Below is an example of using a render target then drawing that rendertarget on screen. You usually don’t want to use rendertargets unless you have very costly drawing operations that are static so you can render them once to the rendertarget and reuse them. Or bacause you wan’t to isolate a scene to run a shader on.

            _renderTarget = new RenderTarget2D(
                GraphicsDevice, 
                (int)size.X, 
                (int)size.Y);
    
            GraphicsDevice.SetRenderTarget(_renderTarget);
            GraphicsDevice.Clear(Color.Transparent);
    
            SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
    
            //draw some stuff.
    
            SpriteBatch.End()
    
            GraphicsDevice.SetRenderTarget(null);
    
            GraphicsDevice.Clear(Color.Blue);
    
            SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
    
            SpriteBatch.Draw(_renderTarget, Vector2.Zero, Color.white);
    
            SpriteBatch.End()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is difference between Session.Clear() vs. Session.Contents.Clear()? I want to clear all the Session
First of all, I want to be clear that I'm not talking about defining
I want to clear/remove ALL the contents of a Grid including RowDefinitions, how can
Can't seem to achieve this simple functionality! All I want is to clear a
First of all, I want to make something clear before I get yelled at:
In SQL Server when I want to check performance, I clear all buffers -
All I want to do is return the index of the i that is
I want to clear all the notification present in my device, notifications from other
I want to clear all values on a form where the control is a
I have groupbox I want to clear all the control in it , I

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.