Пример #1
0
        public void SimpleVG(GraphicsDevice device)
        {
            ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f));

            // We first create all needed fills.
            SolidFill solidFill = new SolidFill();

            solidFill.Colour = Colour.LightBlue;


            GradientFill graFill = GradientFill.CreateGradient(
                new Colour[] { new Colour(13, 185, 242, 255), new Colour(191, 234, 21, 255),
                               new Colour(112, 62, 193, 255), new Colour(255, 242, 81, 255) },
                new float[] { 0.30f, 0.60f }, new Vector2f(1, 1));


            TextureFill texFill = new TextureFill(CreateSampleTexture());

            RadialFill radFill = new RadialFill(new Vector2f(0.75f, 0.75f), 0.15f, Colour.White, Colour.Black);

            Quad2f rect  = new Quad2f(Vector2f.Zero, new Vector2f(0.5f, 0), new Vector2f(0.5f, 0.5f), new Vector2f(0.0f, 0.5f));
            Quad2f rect2 = new Quad2f(new Vector2f(0.5f, 0.5f), new Vector2f(1, 0.5f), new Vector2f(1, 1), new Vector2f(0.5f, 1.0f));


            bool exit = false;

            device.SwapChain.Window.Closed += delegate(Window w) { exit = true; };

            float a = 0;

            while (!exit)
            {
                device.SwapChain.Window.DoEvents();

                using (DeviceLock l = device.Lock())
                {
                    device.Clear(device.SwapChain, Colour.Green);

                    device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height));

                    // We render.
                    canvas.Begin(CanvasRenderFlags.None);


                    canvas.FillShape(solidFill, rect, null);
                    canvas.FillShape(radFill, rect2, null);
                    canvas.Transform = new LinearTransform(
                        new Math.Matrix.Matrix4x4f(Math.MathHelper.Cos(a), -Math.MathHelper.Sin(a), 0, 0,
                                                   Math.MathHelper.Sin(a), Math.MathHelper.Cos(a), 0, 0,
                                                   0, 0, 1, 0,
                                                   0, 0, 0, 1));
                    canvas.FillShape(graFill, rect, null);
                    canvas.FillShape(texFill, rect2, null);



                    canvas.End();
                }


                Console.WriteLine("FPS: {0}\nTrig Count: {1}", device.DevicePerformance.CurrentFPS,
                                  device.DevicePerformance.MaxTrianglesPerFrame);

                a += 0.003f;

                device.SwapChain.Present();
            }

            texFill.Texture.Dispose();
        }
Пример #2
0
        public void FontRendering(GraphicsDevice device)
        {
            ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f));

            // We first create all needed fills.
            RadialFill solidFill = new RadialFill(new Vector2f(0.2f, 0.3f), .4f, Colour.Blue, Colour.LightBlue);
            Font       font      = new Font(SVGFontProvider.ImportSVG("vera.svg"));

            Pen pen = new Pen(solidFill, 0.01f, 0.0f, OutlineEnd.Square);

            bool exit = false;

            device.SwapChain.Window.Closed += delegate(Window w) { exit = true; };

            float a = 0;

            while (!exit)
            {
                device.SwapChain.Window.DoEvents();

                using (DeviceLock l = device.Lock())
                {
                    device.Clear(device.SwapChain, Colour.Green);

                    device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height));

                    // We render.
                    canvas.Begin(CanvasRenderFlags.None);

                    canvas.PixelErrorTolerance = 0.01f + 0.001f * a;

                    Vector2f[] polygon1 = new Vector2f[]
                    {
                        new Vector2f(0.1f, 0.1f),
                        new Vector2f(0.9f, 0.1f),
                        new Vector2f(0.9f, 0.9f),
                        new Vector2f(0.15f, 0.9f),
                        new Vector2f(0.5f, 0.5f),
                        new Vector2f(0.2f, 0.5f),
                        new Vector2f(0.1f, 0.9f)
                    };

                    Vector2f[] polygon2 = new Vector2f[]
                    {
                        new Vector2f(0, 0),
                        new Vector2f(0.1f, 0f),
                        new Vector2f(0.2f, 0.2f),
                        new Vector2f(0.54f, 0.2f),
                        new Vector2f(0.61f, 0.0f),
                        new Vector2f(0.72f, 0.0f),
                        new Vector2f(0.42f, 0.8f),
                        new Vector2f(0.37f, 0.7f),
                        new Vector2f(0.51f, 0.29f),
                        new Vector2f(0.22f, 0.3f),
                        new Vector2f(0.37f, 0.71f),
                        new Vector2f(0.42f, 0.81f),
                        new Vector2f(0.3f, 0.8f)
                    };


                    canvas.FillShape(solidFill, new Polygon2f(polygon2), null);

                    //canvas.FillShape(solidFill, polygon2);
                    //canvas.DrawShape(pen, outline);

                    canvas.End();
                }

                device.SwapChain.Present();

                a += 0.01f;
            }
        }