Esempio n. 1
0
        //*/

        /// <summary>
        /// Test create render to texture
        /// </summary>
        public static void TestCreateRenderToTexture()
        {
            Model testModel = null;
            RenderToTexture renderToTexture = null;

            TestGame.Start(
                "TestCreateRenderToTexture",
                delegate
                {
                    testModel = new Model("apple");
                    renderToTexture = new RenderToTexture(
                        //SizeType.QuarterScreen);
                        SizeType.HalfScreen);
                        //SizeType.HalfScreenWithZBuffer);
                        //SizeType.FullScreen);
                        //SizeType.ShadowMap);
                },
                delegate
                {
                    bool renderToTextureWay =
                        Input.Keyboard.IsKeyUp(Keys.Space) &&
                        Input.GamePadAPressed == false;
                    BaseGame.Device.RenderState.DepthBufferEnable = true;

                    if (renderToTextureWay)
                    {
                        // Set render target to our texture
                        renderToTexture.SetRenderTarget();

                        // Clear background
                        renderToTexture.Clear(Color.Blue);

                        // Draw background lines
                        //Line.DrawGrid();
                        //Ui.LineManager.RenderAll3DLines();

                        // And draw object
                        testModel.Render(Matrix.CreateScale(7.5f));
                        //BaseGame.RenderManager.RenderAllMeshes();

                        // Do we need to resolve?
                        renderToTexture.Resolve(true);
                        //BaseGame.Device.ResolveRenderTarget(0);

                        // Reset background buffer
                        //not longer required, done in Resolve now:
                        //RenderToTexture.ResetRenderTarget(true);
                    } // if (renderToTextureWay)
                    else
                    {
                        // Copy backbuffer way, render stuff normally first
                        // Clear background
                        BaseGame.Device.Clear(Color.Blue);

                        // Draw background lines
                        //Line.DrawGrid();
                        //Ui.LineManager.RenderAll3DLines();

                        // And draw object
                        testModel.Render(Matrix.CreateScale(7.5f));
                        //BaseGame.RenderManager.RenderAllMeshes();
                    } // else

                    // Show render target in a rectangle on our screen
                    renderToTexture.RenderOnScreen(
                        //tst:
                        new Rectangle(100, 100, 256, 256));
                    //BaseGame.ScreenRectangle);
                    //no need: BaseGame.UI.FlushUI();

                    TextureFont.WriteText(2, 0,
                        "               Press Space to toogle full screen rendering");
                    TextureFont.WriteText(2, 30,
                        "renderToTexture.Width=" + renderToTexture.Width);
                    TextureFont.WriteText(2, 60,
                        "renderToTexture.Height=" + renderToTexture.Height);
                    TextureFont.WriteText(2, 90,
                        "renderToTexture.Valid=" + renderToTexture.IsValid);
                    TextureFont.WriteText(2, 120,
                        "renderToTexture.XnaTexture=" + renderToTexture.XnaTexture);
                    TextureFont.WriteText(2, 150,
                        "renderToTexture.ZBufferSurface=" + renderToTexture.ZBufferSurface);
                    TextureFont.WriteText(2, 180,
                        "renderToTexture.Filename=" + renderToTexture.Filename);
                });
        }