Пример #1
0
        /// <summary>
        /// Renders the current scene in a single viewport
        /// </summary>
        /// <param name="renderSurface">The view that is to be rendered too</param>
        public void RenderSingleView(IRenderSurface renderSurface)
        {
            // make sure the device is initialised and that the view is initialised
            if ((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed))
            {
                // get the backbuffer of the surface that is to be rendered to
                Surface surface = renderSurface.SwapChain.GetBackBuffer(0, BackBufferType.Mono);

                // set the device so it renders to the back buffer
                device.SetRenderTarget(0, surface);

                surface.ReleaseGraphics();

                device.DepthStencilSurface = renderSurface.DepthStencil;

                // get the camera that current render surface is using
                MidgetCameras.MidgetCamera camera = renderSurface.Camera;

                // adjust the device camera
                device.Transform.View       = camera.ViewMatrix;
                device.Transform.Projection = camera.ProjectionMatrix;

                //device.PresentationParameters.DeviceWindow.

                // clear the backbuffer
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0);

                // setup the render quality for the viewport
                SetupDrawMode(renderSurface.DrawMode);

                // start drawing the scene
                device.BeginScene();

                // render the scene
                //device.Transform.World = Matrix.Identity;
                SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex);

                // display viewport description text
                Microsoft.DirectX.Direct3D.Font viewportD3DFont
                    = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold));
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30),
                                         DrawTextFormat.Left, Color.Black);
                // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30),
                                         DrawTextFormat.Left, Color.White);
                viewportD3DFont.Dispose();

                // end the scene and display it
                device.EndScene();
                renderSurface.SwapChain.Present();
            }
        }
Пример #2
0
        /// <summary>
        /// Renders the current scene in a single viewport
        /// </summary>
        /// <param name="renderSurface">The view that is to be rendered too</param>
        public void RenderSingleView(IRenderSurface renderSurface)
        {
            // make sure the device is initialised and that the view is initialised
            if((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed))
            {

                // get the backbuffer of the surface that is to be rendered to
                Surface surface =  renderSurface.SwapChain.GetBackBuffer(0,BackBufferType.Mono);

                // set the device so it renders to the back buffer
                device.SetRenderTarget(0,surface);

                surface.ReleaseGraphics();

                device.DepthStencilSurface = renderSurface.DepthStencil;

                // get the camera that current render surface is using
                MidgetCameras.MidgetCamera camera = renderSurface.Camera;

                // adjust the device camera
                device.Transform.View = camera.ViewMatrix;
                device.Transform.Projection = camera.ProjectionMatrix;

                //device.PresentationParameters.DeviceWindow.

                // clear the backbuffer
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0);

                // setup the render quality for the viewport
                SetupDrawMode(renderSurface.DrawMode);

                // start drawing the scene
                device.BeginScene();

                // render the scene
                //device.Transform.World = Matrix.Identity;
                SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex);

                // display viewport description text
                Microsoft.DirectX.Direct3D.Font viewportD3DFont
                    = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold));
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30),
                    DrawTextFormat.Left, Color.Black);
                // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30),
                    DrawTextFormat.Left, Color.White);
                viewportD3DFont.Dispose();

                // end the scene and display it
                device.EndScene();
                renderSurface.SwapChain.Present();
            }
        }