Beispiel #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();
            }
        }
Beispiel #2
0
        void Draw(Device device)
        {
            try
            {
                System.Drawing.Rectangle rect;
                // start drawing commands
                device.BeginScene();


                // Demonstration 1
                // Draw a simple line using DrawText
                // Pass in DrawTextFormat.NoClip so we don't have to calc
                // the bottom/right of the rect

                font1.DrawText(null,
                               "This is a trivial call to Font.DrawText",
                               new System.Drawing.Rectangle(5, 150, 0, 0),
                               DrawTextFormat.NoClip, System.Drawing.Color.Red);


                // Demonstration 2
                // Allow multiple draw calls to sort by texture changes
                // by Sprite When drawing 2D text use flags:
                // SpriteFlags.AlphaBlend | SpriteFlags.SortTexture.

                textDrawerSprite.Begin(SpriteFlags.AlphaBlend |
                                       SpriteFlags.SortTexture);

                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 6, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "These are multiple calls to Font.DrawText()",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 5, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "using the same Sprite. The font now caches",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 4, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "letters on one or more textures. In order",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 3, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "to sort by texturestate changes on multiple",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 2, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "calls to DrawText() pass a Sprite and use flags",
                               rect, DrawTextFormat.NoClip, Color.White);
                rect = new System.Drawing.Rectangle(5, this.screenheight - 15 * 1, 0, 0);
                font2.DrawText(textDrawerSprite,
                               "SpriteFlags.AlphaBlend | SpriteFlags.SortTexture",
                               rect, DrawTextFormat.NoClip, Color.White);

                textDrawerSprite.End();

                // Demonstration 3:
                // Word wrapping and unicode text.
                // Note that not all fonts support dynamic font linking.
                System.Drawing.Rectangle rc =
                    new System.Drawing.Rectangle(10, 35,
                                                 this.screenwidth - 30, this.screenheight - 10);

                font2.DrawText(null, bigText, rc,
                               DrawTextFormat.Left | DrawTextFormat.WordBreak |
                               DrawTextFormat.ExpandTabs,
                               System.Drawing.Color.CornflowerBlue);

                // write the fps
                //fpsTimer.Render();
                OnRender( );
            }

            finally
            {
                // end the drawing commands and copy to screen
                device.EndScene();
                device.Present();
                //fpsTimer.StopFrame();
            }


            sprite.Begin(SpriteFlags.None);
            sprite.Draw(texture,
                        new Rectangle(0, 0, 512, 512),
                                                          //new Vector2( 1.0f, 1.0f ), // scaling
                        new Vector3(256.0f, 256.0f, 0.0f) //rotation center
                                                          //,0.0f // rogateion
                        , new Vector3(0.0f, 0.0f, 0.0f)   // translation
                        , Color.White                     // color
                        );
            sprite.End();
        }
Beispiel #3
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();
            }
        }