Пример #1
0
        protected internal override void Draw(RenderTarget renderTarget)
        {
            DrawingStateBlock stateBlock = d2DFactory.CreateDrawingStateBlock();

            renderTarget.SaveDrawingState(stateBlock);
            //AntialiasMode push = RenderTarget.AntialiasMode;
            renderTarget.AntiAliasMode = AntiAliasMode.Aliased;
            renderTarget.FillMesh(mesh, FillBrush);
            //RenderTarget.AntialiasMode = push;
            renderTarget.RestoreDrawingState(stateBlock);
            stateBlock.Dispose();
        }
        private void renderPoints(SharpDX.Vector2 [] points)
        {
            using (DrawingStateBlock block = new DrawingStateBlock(d2dFactory))
            {
                d2dRenderTarget.SaveDrawingState(block);

                foreach (Vector2 point in points)
                {
                    d2dRenderTarget.Transform = Matrix3x2.Translation(point) * this.transformation;
                    d2dRenderTarget.DrawGeometry(this.facePointGeometry, facePointBrush);
                }

                d2dRenderTarget.RestoreDrawingState(block);
            }
        }
Пример #3
0
        protected internal override void Draw(RenderTarget renderTarget)
        {
            DrawingStateBlock stateBlock = d2DFactory.CreateDrawingStateBlock();

            renderTarget.SaveDrawingState(stateBlock);
            renderTarget.TextRenderingParams = RenderingParams;

            if (Options.HasValue)
            {
                renderTarget.DrawText(Text, TextFormat, layoutRect, FillBrush, Options.Value);
            }
            else
            {
                renderTarget.DrawText(Text, TextFormat, layoutRect, FillBrush);
            }

            renderTarget.RestoreDrawingState(stateBlock);
            stateBlock.Dispose();
        }
        public PumpkinFaceRenderer(IFaceCamera <System.Drawing.PointF> faceCamera)
        {
            renderForm = new RenderForm("Calabasas");
            renderForm.AllowUserResizing = true;

            this.faceCamera = faceCamera;

            renderForm.KeyPress += OnRenderFormKeyPress;

            renderForm.MouseClick += OnRenderFormMouseClick;

            if (this.faceCamera != null)
            {
                this.faceCamera.OnFaceChanged  += OnFaceChanged;
                this.faceCamera.OnTrackingFace += OnTrackingFace;
            }

            // SwapChain description
            swapChainDesc = new SwapChainDescription()
            {
                BufferCount     = 1,
                ModeDescription = new ModeDescription(Width, Height,
                                                      new Rational(60, 1), Format.R8G8B8A8_UNorm),
                IsWindowed        = true,
                OutputHandle      = renderForm.Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device and SwapChain
            SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new SharpDX.Direct3D.FeatureLevel[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, swapChainDesc, out device, out swapChain);

            d2dFactory = new SharpDX.Direct2D1.Factory();
            dwFactory  = new SharpDX.DirectWrite.Factory();

            // Ignore all windows events
            SharpDX.DXGI.Factory factory = swapChain.GetParent <SharpDX.DXGI.Factory>();
            factory.MakeWindowAssociation(renderForm.Handle, WindowAssociationFlags.IgnoreAll);

            // New RenderTargetView from the backbuffer
            backBuffer       = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
            renderTargetView = new RenderTargetView(device, backBuffer);

            surface = backBuffer.QueryInterface <Surface>();

            d2dRenderTarget = new RenderTarget(
                d2dFactory,
                surface,
                new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)));

            // Initialize a TextFormat
            TextFormat = new TextFormat(dwFactory, "Calibri", 18);

            d2dRenderTarget.TextAntialiasMode = SharpDX.Direct2D1.TextAntialiasMode.Cleartype;

            // Initialize a Brush.
            SceneColorBrush = new SolidColorBrush(d2dRenderTarget, Color.White);

            // Initialize geometery/drawable primitives.
            facePointGeometry = new RectangleGeometry(d2dFactory, new SharpDX.Mathematics.Interop.RawRectangleF(-PointSize / 2.0F, -PointSize / 2.0F, PointSize / 2.0F, PointSize / 2.0F));
            facePointBrush    = new SolidColorBrush(d2dRenderTarget, new SharpDX.Color(facePointPenColor.R, facePointPenColor.G, facePointPenColor.B));

            drawingStateBlock = new DrawingStateBlock(d2dFactory);

            framesPerSecond = new FramesPerSecond();
        }