//*/ /// <summary> /// Test create render to texture /// </summary> public static void TestCreateRenderToTexture() { ColladaModel testModel = null; RenderToTexture renderToTexture = null; TestGame.Start( "TestCreateRenderToTexture", delegate { testModel = new ColladaModel("Sword"); renderToTexture = new RenderToTexture( //SizeType.QuarterScreen); SizeType.HalfScreen); //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); /*obs // Draw background lines BaseGame.DrawLine(new Point(0, 200), new Point(200, 0), Color.Blue); BaseGame.DrawLine(new Point(0, 0), new Point(400, 400), Color.Red); BaseGame.FlushLineManager2D(); */ // And draw object testModel.Render(Matrix.CreateScale(1.5f)); //obs: BaseGame.MeshRenderManager.Render(); // Do we need to resolve? renderToTexture.Resolve(); //BaseGame.Device.ResolveRenderTarget(0); // Reset background buffer BaseGame.ResetRenderTarget(true); } // if (renderToTextureWay) else { // Copy backbuffer way, render stuff normally first // Clear background BaseGame.Device.Clear(Color.Blue); /*obs // Draw background lines BaseGame.DrawLine(new Point(0, 200), new Point(200, 0), Color.Blue); BaseGame.DrawLine(new Point(0, 0), new Point(400, 400), Color.Red); BaseGame.FlushLineManager2D(); */ // And draw object testModel.Render(Matrix.CreateScale(1.5f)); //obs: BaseGame.MeshRenderManager.Render(); } // else // Show render target in a rectangle on our screen renderToTexture.RenderOnScreen( //tst: new Rectangle(100, 100, 256, 256)); //BaseGame.ResolutionRect); //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.Valid); TextureFont.WriteText(2, 120, "renderToTexture.XnaTexture=" + renderToTexture.XnaTexture); TextureFont.WriteText(2, 150, "renderToTexture.ZBufferSurface=" + renderToTexture.ZBufferSurface); TextureFont.WriteText(2, 180, "renderToTexture.Filename=" + renderToTexture.Filename); }); }