#
RenderTarget2D OverviewA RenderTarget2D
is like a special kind of texture that we can draw things too. So instead of drawing our scene directly to the game window (aka backbuffer), we're instead going to draw our scene to a render target. By doing this, when we do our scene transitions, we can manipulate the render target before we draw it the the screen to create the transition effects.
There are a few caveats to using render targets that we need to be aware of, and we need to make sure that we handle them properly.
- A
RenderTarge2D
instance is a graphical resource object that we are creating manually. This means its life cycle is not managed by theContentManager
like a normal textures, and we'll need to handle disposing of it properly when no longer needed. - The contents of the
RenderTarget2D
when we draw to it reside in VRAM. Due to this, anytime aGraphicsDevice.DeviceCreated
orGraphicsDevice.DeviceReset
event occurs, all contents of VRAM are discarded and theRenderTarget2D
instance will need to be recreated again. (this isn't as scary as it sounds).
So, with these points in mind, let's get started updating our scene demo.