コード例 #1
0
        public override void Load()
        {
            //draw 1
            FormTestWinGLControl form = new FormTestWinGLControl();
            var canvas = PixelFarm.Drawing.DrawingGL.CanvasGLPortal.P.CreateCanvas(0, 0, 800, 600);

            PixelFarm.Drawing.Bitmap       bmp    = null;
            PixelFarm.Drawing.TextureBrush tbrush = null;
            form.SetGLPaintHandler((o, s) =>
            {
                canvas.ClearSurface(PixelFarm.Drawing.Color.White);
                if (tbrush == null)
                {
                    var bitmap = new System.Drawing.Bitmap("../../../SampleImages/plain01.png");
                    bmp        = new PixelFarm.Drawing.Bitmap(bitmap.Width, bitmap.Height, bitmap);
                    tbrush     = new PixelFarm.Drawing.TextureBrush(bmp);
                }
                //2. fill polygon with gradient brush
                canvas.FillPolygon(
                    tbrush,
                    new PixelFarm.Drawing.PointF[] {
                    new PixelFarm.Drawing.PointF(60, 50),
                    new PixelFarm.Drawing.PointF(100, 50),
                    new PixelFarm.Drawing.PointF(70, 100)
                });
                canvas.Note1 = 1; //temp
                canvas.FillPolygon(
                    tbrush,
                    new PixelFarm.Drawing.PointF[] {
                    new PixelFarm.Drawing.PointF(0, 50),
                    new PixelFarm.Drawing.PointF(50, 50),
                    new PixelFarm.Drawing.PointF(10, 100)
                });
                canvas.Note1 = 0;
                //-------------------------------------------------------------------------
            });
            form.Show();
        }
コード例 #2
0
ファイル: CanvasGL2d.cs プロジェクト: lingliy/HtmlRenderer
        public void FillGfxPath(Drawing.Brush brush, InternalGraphicsPath igpth)
        {
            switch (brush.BrushKind)
            {
            case Drawing.BrushKind.Solid:
            {
                var solidBrush = brush as PixelFarm.Drawing.SolidBrush;
                FillGfxPath(solidBrush.Color, igpth);
            }
            break;

            case Drawing.BrushKind.LinearGradient:
            case Drawing.BrushKind.Texture:
            {
                List <Figure> figures = igpth.figures;
                int           m       = figures.Count;
                for (int b = 0; b < m; ++b)
                {
                    Figure fig = figures[b];
                    GL.ClearStencil(0);         //set value for clearing stencil buffer
                    //actual clear here
                    GL.Clear(ClearBufferMask.StencilBufferBit);
                    //-------------------
                    //disable rendering to color buffer
                    GL.ColorMask(false, false, false, false);
                    //start using stencil
                    GL.Enable(EnableCap.StencilTest);
                    //place a 1 where rendered
                    GL.StencilFunc(StencilFunction.Always, 1, 1);
                    //replace where rendered
                    GL.StencilOp(StencilOp.Replace, StencilOp.Replace, StencilOp.Replace);
                    //render  to stencill buffer
                    //-----------------

                    float[] tessArea = fig.GetAreaTess(ref this.tessTool);
                    //-------------------------------------
                    if (tessArea != null)
                    {
                        this.basicFillShader.FillTriangles(tessArea, fig.TessAreaTriangleCount, PixelFarm.Drawing.Color.Black);
                    }
                    //--------------------------------------
                    //render color
                    //--------------------------------------
                    //reenable color buffer
                    GL.ColorMask(true, true, true, true);
                    //where a 1 was not rendered
                    GL.StencilFunc(StencilFunction.Equal, 1, 1);
                    //freeze stencill buffer
                    GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
                    //------------------------------------------
                    //we already have valid ps from stencil step
                    //------------------------------------------

                    //-------------------------------------------------------------------------------------
                    //1.  we draw only alpha chanel of this black color to destination color
                    //so we use  BlendFuncSeparate  as follow ...
                    //-------------------------------------------------------------------------------------
                    //1.  we draw only alpha channel of this black color to destination color
                    //so we use  BlendFuncSeparate  as follow ...
                    GL.ColorMask(false, false, false, true);
                    //GL.BlendFuncSeparate(
                    //     BlendingFactorSrc.DstColor, BlendingFactorDest.DstColor, //the same
                    //     BlendingFactorSrc.One, BlendingFactorDest.Zero);

                    //use alpha chanel from source***
                    GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.Zero);
                    float[] smoothBorder = fig.GetSmoothBorders();
                    invertAlphaFragmentShader.DrawTriangleStrips(smoothBorder, fig.BorderTriangleStripCount);
                    //at this point alpha component is fill in to destination
                    //-------------------------------------------------------------------------------------
                    //2. then fill again!,
                    //we use alpha information from dest,
                    //so we set blend func to ... GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha)
                    GL.ColorMask(true, true, true, true);
                    GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);
                    {
                        //draw box*** of gradient color
                        switch (brush.BrushKind)
                        {
                        case Drawing.BrushKind.LinearGradient:
                        {
                            var     linearGradientBrush = brush as PixelFarm.Drawing.LinearGradientBrush;
                            var     colors = linearGradientBrush.GetColors();
                            var     points = linearGradientBrush.GetStopPoints();
                            float[] v2f, color4f;
                            GLGradientColorProvider.CalculateLinearGradientVxs2(
                                points[0].X, points[0].Y,
                                points[1].X, points[1].Y,
                                colors[0],
                                colors[1], out v2f, out color4f);
                            rectFillShader.Render(v2f, color4f);
                        }
                        break;

                        case Drawing.BrushKind.Texture:
                        {
                            //draw texture image ***
                            PixelFarm.Drawing.TextureBrush tbrush = (PixelFarm.Drawing.TextureBrush)brush;
                            GLBitmap bmpTexture = PixelFarm.Drawing.Image.GetCacheInnerImage(tbrush.TextureImage) as GLBitmap;
                            //TODO: review here
                            //where text start?
                            this.DrawImage(bmpTexture, 0, 300);
                        }
                        break;
                        }
                    }
                    //restore back
                    //3. switch to normal blending mode
                    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                    GL.Disable(EnableCap.StencilTest);
                }
            }
            break;
            }
        }