protected override void Draw(GameTime gameTime) { // render scene for real GraphicsDevice.SetRenderTarget(PostProcessingManager.SceneTarget); GraphicsDevice.Clear(Graphics.SkyBlue); base.Draw(gameTime); _graphics.PreferMultiSampling = true; //-----3D----- GraphicsDevice.DepthStencilState = DepthStencilState.Default; // new DepthStencilState() { DepthBufferEnable = true }; // activates z buffer HardwareRendering.Draw(); ParticleRendering.Draw(); if (PhysicsDrawer.Instance.DoDrawings) { foreach (Camera cam in Screen.Cameras) { GraphicsDevice.Viewport = cam.Viewport; // Allow physics drawing for debug-reasons (display boundingboxes etc..) PhysicsDrawer.Instance.Draw(cam); //gizmos GraphicsDevice.RasterizerState = Screen._wireRasterizer; Gizmos.DrawWire(cam); GraphicsDevice.RasterizerState = Screen._fullRasterizer; Gizmos.DrawFull(cam); } Gizmos.ClearOrders(); } // draw everything 3D to get the depth info _graphics.GraphicsDevice.SetRenderTarget(PostProcessingManager.DepthTarget); _graphics.GraphicsDevice.Clear(Color.Black); HardwareRendering.DrawDepth(); ParticleRendering.DrawDepth(); // apply post processing PostProcessingManager.Instance.Draw(_spriteBatch); // Drop the render target GraphicsDevice.SetRenderTarget(null); //-----2D----- int i = 0; foreach (Camera cam in Screen.Cameras) { GraphicsDevice.Viewport = cam.Viewport; _spriteBatch.Begin(); if (showUI) { foreach (GameObject go in GameObject.All) { go.Draw2D(i); } } _spriteBatch.End(); i++; } GraphicsDevice.Viewport = Screen.FullViewport; if (showUI) { _spriteBatch.Begin(); foreach (GameObject go in GameObject.All) { go.Draw2D(-1); } _spriteBatch.End(); } if (ShowFps) { try { string text = string.Format( "Frames per second: {0}/{1}\n" + "Instances: {2}\n", (1.0f / gameTime.ElapsedGameTime.TotalSeconds).ToString("0.00"), (_frames++ / gameTime.TotalGameTime.TotalSeconds).ToString("0.00"), GameObject.All.Length); _spriteBatch.Begin(); _spriteBatch.DrawString(_font, text, new Vector2(65, 265), Color.Black); _spriteBatch.DrawString(_font, text, new Vector2(64, 264), Color.White); _spriteBatch.End(); } catch { // Do nothing } } }