Beispiel #1
0
            /// <inheritdoc/>
            public void Run()
            {
                DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;

                // Specify the cursor type as the standard arrow cursor.
                window.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0);

                // Activate the application window, making it visible and enabling it to receive events.
                window.Activate();

                // Enter the render loop.  Note that Metro style apps should never exit.
                while (true)
                {
                    // Process events incoming to the window.
                    window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                    if (window.GetAsyncKeyState(Windows.System.VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                    {
                        break;
                    }

                    // Render the cube
                    target.RenderAll();

                    // Present the cube
                    target.Present();
                }
            }
Beispiel #2
0
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                // Clear the target.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);

                // Draw a block of text that will be clipped against the specified layout rectangle.
                d2dContext.FillRectangle(new RectangleF(50, 50, 200, 200), backgroundBrush);
                d2dContext.DrawText("This text is long enough to overflow the designed region but will be clipped to the containing rectangle. Lorem ipsum dolor sit amet, consectetur adipiscing elit. ", textFormat, new RectangleF(50, 50, 200, 200), textBrush, DrawTextOptions.Clip);

                // Draw a block of text that will overflow the specified layout rectangle.
                d2dContext.FillRectangle(new RectangleF(50, 300, 200, 200), backgroundBrush);
                d2dContext.DrawText("However, this other text isn't going to be clipped: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean gravida dui id accumsan dictum.", textFormat, new RectangleF(50, 300, 200, 200), textBrush, DrawTextOptions.None);

                // Draw three lines of text with different measuring modes.
                d2dContext.FillRectangle(new RectangleF(300, 50, 400, 200), backgroundBrush);
                d2dContext.DrawText("MeasuringMode: Natural", textFormat, new RectangleF(300, 50, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.Natural);
                d2dContext.DrawText("MeasuringMode: GDI classic", textFormat, new RectangleF(300, 80, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.GdiClassic);
                d2dContext.DrawText("MeasuringMode: GDI natural", textFormat, new RectangleF(300, 110, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.GdiNatural);

                float layoutYOffset = (float)Math.Cos(layoutY) * 50.0f;

                // Draw moving text.
                d2dContext.FillRectangle(new RectangleF(300, 300, 400, 200), backgroundBrush);
                d2dContext.DrawTextLayout(new Vector2(300, 350 + layoutYOffset), textLayout1, textBrush);

                // Draw moving text without pixel snapping, thus giving a smoother movement.
                d2dContext.FillRectangle(new RectangleF(750, 300, 400, 200), backgroundBrush);
                d2dContext.DrawTextLayout(new Vector2(750, 350 + layoutYOffset), textLayout2, textBrush, DrawTextOptions.NoSnap);

                d2dContext.EndDraw();
                layoutY += 1.0f / 60.0f;

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Beispiel #3
0
            /// <inheritdoc/>
            public void Run()
            {
                // Activate the application window, making it visible and enabling it to receive events.
                window.Activate();

                // Prepare matrices
                var view     = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
                var proj     = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, width / (float)height, 0.1f, 100.0f);
                var viewProj = Matrix.Multiply(view, proj);

                // Enter the render loop.  Note that Metro style apps should never exit.
                while (true)
                {
                    // Process events incoming to the window.
                    window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                    if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                    {
                        break;
                    }

                    // Gets the current graphics context
                    var graphicsContext = graphicsDevice.ImmediateContext;

                    var time = (float)(clock.ElapsedMilliseconds / 1000.0);

                    // Set targets (This is mandatory in the loop)
                    graphicsContext.OutputMerger.SetTargets(renderTargetView);

                    // Clear the views
                    graphicsContext.ClearRenderTargetView(renderTargetView, Color.CornflowerBlue);

                    // Calculate WorldViewProj
                    Matrix worldViewProj = Matrix.RotationX(time) * Matrix.RotationY(time * 2.0f) * Matrix.RotationZ(time * .7f) * viewProj;
                    worldViewProj.Transpose();

                    // Setup the pipeline
                    graphicsContext.InputAssembler.SetVertexBuffers(0, vertexBufferBinding);
                    graphicsContext.InputAssembler.InputLayout       = layout;
                    graphicsContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                    graphicsContext.VertexShader.SetConstantBuffer(0, constantBuffer);
                    graphicsContext.VertexShader.Set(vertexShader);
                    graphicsContext.PixelShader.Set(pixelShader);

                    // Update Constant Buffer
                    graphicsContext.UpdateSubresource(ref worldViewProj, constantBuffer, 0);

                    // Draw the cube
                    graphicsContext.Draw(36, 0);

                    // Present the backbuffer
                    swapChain.Present(1, PresentFlags.None, new PresentParameters());
                }
            }
Beispiel #4
0
            /// <inheritdoc/>
            public void Run()
            {
                DisplayProperties.LogicalDpiChanged += DisplayProperties_LogicalDpiChanged;

                // Specify the cursor type as the standard arrow cursor.
                window.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0);

                // Activate the application window, making it visible and enabling it to receive events.
                window.Activate();

                // Run this method async
                // But because It was not possible to use correctly async here
                // we have to use a lock approach, which is far from ideal, but it is at least working.
                // The problem is described here: http://social.msdn.microsoft.com/Forums/mr-IN/winappswithcsharp/thread/d09dd944-f92b-484d-b2ef-d1850c4a587f
                RunAsync();

                // Enter the render loop.  Note that Metro style apps should never exit.
                while (true)
                {
                    // Process events incoming to the window.
                    window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                    if (window.GetAsyncKeyState(Windows.System.VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                    {
                        break;
                    }

                    bool isInitOk = false;

                    // Check if initialization is done
                    lock (this)
                    {
                        isInitOk = IsInitialized;
                    }

                    // If done, perform rendering
                    if (isInitOk)
                    {
                        // Render the cube
                        target.RenderAll();

                        // Present the cube
                        target.Present();
                    }
                }
            }
Beispiel #5
0
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                // Clear the target and draw some geometry with the brushes we created.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);

                // Calculate the center of the screen
                int halfWidth  = this.swapChain.Description.ModeDescription.Width / 2;
                int halfHeight = this.swapChain.Description.ModeDescription.Height / 2;

                // Translate the origin of coordinates for drawing the bitmap filled rectangle
                d2dContext.Transform = Matrix3x2.Translation(halfWidth - 350, halfHeight);
                d2dContext.FillRectangle(new RectangleF(0, 0, 700, 70), terrainBrush);

                // Translate again for drawing the player bitmap
                d2dContext.Transform = Matrix3x2.Translation(halfWidth, halfHeight - playerBitmap.Size.Height);
                d2dContext.DrawBitmap(playerBitmap, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
                d2dContext.EndDraw();

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Run our application until the user quits.
        /// </summary>
        public void Run()
        {
            // Make window active and hide mouse cursor.
            window.PointerCursor = null;
            window.Activate();

            // Infinite loop to prevent the application from exiting.
            while (true)
            {
                // Dispatch all pending events in the queue.
                window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                // Quit if the users presses Escape key.
                if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down)
                {
                    return;
                }

                // Set the Direct2D drawing target.
                d2dContext.Target = d2dTarget;

                // Clear the target and draw some geometry with the brushes we created.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);
                d2dContext.FillRectangle(new RectangleF(50, 50, 450, 150), solidBrush);
                d2dContext.FillRoundedRectangle(new RoundedRectangle()
                {
                    Rect    = new RectangleF(50, 250, 450, 150),
                    RadiusX = 10,
                    RadiusY = 10
                }, linearGradientBrush);
                d2dContext.FillEllipse(new Ellipse(new Vector2(250, 525), 100, 100), radialGradientBrush);
                d2dContext.EndDraw();

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }