Rendering to a 2D texture is a cool thing, and allows
you to create some amazing effects. Once such example is
your 3d world to a seperate texture, then using that texture to either
blur/stretch or modify your image, or even wrap your texture onto an
object! Of course where getting to the world of reflections and
shinny objects, but you can render the world from the perspective of an
to a texture. Then render your world with your object in it, but
mapping the texture on it, so it looks like its super reflective or
made of mirrors!
But where going to do something simple here, showing the principles of
rendering to a texture as the focus point, I'll create a 3d menu and
render it to a texture then display it :)
The main parts of the code, the meat and potatoes as
they say, is shown in snippet form below.
|Code Snippet : Render Target
PresentationParameters pp = graphicsDevice.PresentationParameters;
RenderTarget2D renderTarget = new RenderTarget2D(graphicsDevice,
///>graphicsDevice.DisplayMode.Format< ALPHA PROBLEMS --+
/// If you use the graphicDevices colour format 'graphicsDevice.DisplayMode.Format', then you
/// might notice if you use alphas that your alphas dont work.
graphicsDevice.SetRenderTarget(0, renderTarget); /// Switch to our render target
graphicsDevice.Clear(Color.TransparentBlack); /// Clear it
/// Draw anything we want here!!
graphicsDevice.SetRenderTarget(0, null); /// Set main render target back
Texture2D renderTexture = renderTarget.GetTexture();/// Get our texture2d
Of course this is just to show you the main functions, you'd only
new the RenderTarget2D when you needed it once, and I've pointed out
that if you dont set the Color format correctly you'll have a problem
with your alpha's ;)