Displaying the Rear-View Mirror

Now that you have the scene rendered into your texture, it should be a simple matter to get that displayed onscreen. Because it is a single texture, you can re-use the sprite class you used for the background of the user screen to render the rear-view mirror. In the OnFrameRender method, find the call to RenderScene and add this code snippet, which should show you a scene similar to Figure 22.3:

// Render the rear-view mirror texture
backgroundSprite.Begin(SpriteFlags.None);
backgroundSprite.Draw2D(rearTexture, System.Drawing.Rectangle.Empty,
    new System.Drawing.Rectangle(0,0,256,128), new System.Drawing.Point(200, 0),
    unchecked((int)0xffffffff));
backgroundSprite.End();
Figure 22.3. A rear-view mirror.

Get Beginning 3D Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.