Example #1
0
 void AddBezier(double x1, double y1,
                double x2, double y2,
                double x3, double y3)
 {
     m_points.AddVertex(new Vector2(x1, y1));
     AddRecursiveBezier(x1, y1, x2, y2, x3, y3, 0);
     m_points.AddVertex(new Vector2(x3, y3));
 }
Example #2
0
        static unsafe void CreateLineCoords(ArrayList <VertexC4V3f> vrx,
                                            PixelFarm.Drawing.Color color,
                                            float x1, float y1, float x2, float y2)
        {
            uint color_uint = color.ToABGR();

            vrx.AddVertex(new VertexC4V3f(color_uint, x1, y1));
            vrx.AddVertex(new VertexC4V3f(color_uint, x2, y2));
        }
Example #3
0
        public void AddVertex(LineAAVertex val)
        {
            int count = list.Count;

            if (count > 1)
            {
                var innerArray = list.Array;
                if (!innerArray[count - 2].IsDiff(innerArray[count - 1]))
                {
                    list.RemoveLast();
                }
            }
            list.AddVertex(val);
        }
Example #4
0
 static void AddRect(ArrayList <VertexC4V3f> vrx,
                     uint c1, uint c2,
                     float x, float y,
                     float w, float h)
 {
     //horizontal gradient
     vrx.AddVertex(new VertexC4V3f(c1, x, y));
     vrx.AddVertex(new VertexC4V3f(c2, x + w, y));
     vrx.AddVertex(new VertexC4V3f(c2, x + w, y + h));
     vrx.AddVertex(new VertexC4V3f(c2, x + w, y + h));
     vrx.AddVertex(new VertexC4V3f(c1, x, y + h));
     vrx.AddVertex(new VertexC4V3f(c1, x, y));
 }
 static void AddRect(ArrayList<VertexC4V3f> vrx,
     uint c1, uint c2,
     float x, float y,
     float w, float h)
 {
     //horizontal gradient
     vrx.AddVertex(new VertexC4V3f(c1, x, y));
     vrx.AddVertex(new VertexC4V3f(c2, x + w, y));
     vrx.AddVertex(new VertexC4V3f(c2, x + w, y + h));
     vrx.AddVertex(new VertexC4V3f(c2, x + w, y + h));
     vrx.AddVertex(new VertexC4V3f(c1, x, y + h));
     vrx.AddVertex(new VertexC4V3f(c1, x, y));
 }
        static unsafe void CreateRectCoords(ArrayList <VertexC4V3f> vrx,
                                            PixelFarm.Drawing.Color color,
                                            float x, float y, float w, float h)
        {
            uint color_uint = color.ToABGR();

            vrx.AddVertex(new VertexC4V3f(color_uint, x, y));
            vrx.AddVertex(new VertexC4V3f(color_uint, x + w, y));
            vrx.AddVertex(new VertexC4V3f(color_uint, x + w, y + h));
            vrx.AddVertex(new VertexC4V3f(color_uint, x + w, y + h));
            vrx.AddVertex(new VertexC4V3f(color_uint, x, y + h));
            vrx.AddVertex(new VertexC4V3f(color_uint, x, y));
        }
Example #7
0
        public void FillPolygon(PixelFarm.Drawing.Brush brush, float[] vertex2dCoords, int npoints)
        {
            //-------------
            //Tesselate
            //2d coods lis
            //n point
            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                //closed polygon

                //closed polygon
                int j = npoints / 2;
                //first point
                if (j < 2)
                {
                    return;
                }
                ps.MoveTo(vertex2dCoords[0], vertex2dCoords[1]);
                int nn = 2;
                for (int i = 1; i < j; ++i)
                {
                    ps.LineTo(vertex2dCoords[nn++],
                              vertex2dCoords[nn++]);
                }
                //close
                ps.CloseFigure();
                VertexStore vxs = ps.Vxs;
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                switch (brush.BrushKind)
                {
                case Drawing.BrushKind.Solid:
                {
                    var color = ((PixelFarm.Drawing.SolidBrush)brush).Color;
                    sclineRasToGL.FillWithColor(sclineRas, sclinePack8, color);
                }
                break;

                default:
                {
                }
                break;
                }
            }
            break;

            default:
            {
                var vertextList = TessPolygon(vertex2dCoords);
                //-----------------------------
                //switch how to fill polygon
                switch (brush.BrushKind)
                {
                case Drawing.BrushKind.LinearGradient:
                case Drawing.BrushKind.Texture:
                {
                    var linearGradientBrush = brush as PixelFarm.Drawing.LinearGradientBrush;
                    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
                    //-----------------
                    if (this.Note1 == 1)
                    {
                        ////create stencil with Agg shape
                        int j = npoints / 2;
                        //first point
                        if (j < 2)
                        {
                            return;
                        }
                        ps.Clear();
                        ps.MoveTo(vertex2dCoords[0], vertex2dCoords[1]);
                        int nn = 2;
                        for (int i = 1; i < j; ++i)
                        {
                            ps.LineTo(
                                vertex2dCoords[nn++],
                                vertex2dCoords[nn++]);
                        }
                        //close
                        ps.CloseFigure();
                        VertexStore vxs = ps.Vxs;
                        sclineRas.Reset();
                        sclineRas.AddPath(vxs);
                        sclineRasToGL.FillWithColor(sclineRas, sclinePack8, PixelFarm.Drawing.Color.White);
                        //create stencil with normal OpenGL
                    }
                    else
                    {
                        //create stencil with normal OpenGL
                        int j  = vertextList.Count;
                        int j2 = j * 2;
                        //VboC4V3f vbo = GenerateVboC4V3f();
                        ArrayList <VertexC4V2f> vrx = new ArrayList <VertexC4V2f>();
                        uint color_uint             = PixelFarm.Drawing.Color.Black.ToABGR();       //color.ToABGR();
                        for (int i = 0; i < j; ++i)
                        {
                            var v = vertextList[i];
                            vrx.AddVertex(new VertexC4V2f(color_uint, (float)v.m_X, (float)v.m_Y));
                        }

                        DrawVertexList(DrawMode.Triangles, vrx, vrx.Count);
                    }
                    //--------------------------------------
                    //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);
                    if (this.Note1 == 1)
                    {
                        //------------------------------------------
                        //we already have valid ps from stencil step
                        //------------------------------------------
                        VertexStore vxs = ps.Vxs;
                        sclineRas.Reset();
                        sclineRas.AddPath(vxs);
                        //-------------------------------------------------------------------------------------
                        //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);
                        sclineRasToGL.FillWithColor(sclineRas, sclinePack8, PixelFarm.Drawing.Color.Black);
                        //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
                            if (brush.BrushKind == Drawing.BrushKind.LinearGradient)
                            {
                                var  colors = linearGradientBrush.GetColors();
                                var  points = linearGradientBrush.GetStopPoints();
                                uint c1     = colors[0].ToABGR();
                                uint c2     = colors[1].ToABGR();
                                //create polygon for graident bg

                                ArrayList <VertexC4V2f>
                                vrx = GLGradientColorProvider.CalculateLinearGradientVxs(
                                    points[0].X, points[0].Y,
                                    points[1].X, points[1].Y,
                                    colors[0],
                                    colors[1]);
                                DrawVertexList(DrawMode.Triangles, vrx, vrx.Count);
                            }
                            else if (brush.BrushKind == Drawing.BrushKind.Texture)
                            {
                                //draw texture image
                                PixelFarm.Drawing.TextureBrush tbrush = (PixelFarm.Drawing.TextureBrush)brush;
                                PixelFarm.Drawing.Image        img    = tbrush.TextureImage;
                                GLBitmap bmpTexture = (GLBitmap)tbrush.InnerImage2;
                                this.DrawImage(bmpTexture, 0, 0);
                                //GLBitmapTexture bmp = GLBitmapTexture.CreateBitmapTexture(fontGlyph.glyphImage32);
                                //this.DrawImage(bmp, 0, 0);
                                //bmp.Dispose();
                            }
                        }
                        //restore back
                        //3. switch to normal blending mode
                        GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                    }
                    else
                    {
                        //draw box of gradient color
                        var  colors = linearGradientBrush.GetColors();
                        var  points = linearGradientBrush.GetStopPoints();
                        uint c1     = colors[0].ToABGR();
                        uint c2     = colors[1].ToABGR();
                        //create polygon for graident bg
                        var vrx = GLGradientColorProvider.CalculateLinearGradientVxs(
                            points[0].X, points[0].Y,
                            points[1].X, points[1].Y,
                            colors[0],
                            colors[1]);
                        DrawVertexList(DrawMode.Triangles, vrx, vrx.Count);
                    }
                    GL.Disable(EnableCap.StencilTest);
                }
                break;

                default:
                {
                    //unknown brush
                    //int j = vertextList.Count;
                    //int j2 = j * 2;
                    //VboC4V3f vbo = GenerateVboC4V3f();
                    //ArrayList<VertexC4V3f> vrx = new ArrayList<VertexC4V3f>();
                    //uint color_int = color.ToABGR();
                    //for (int i = 0; i < j; ++i)
                    //{
                    //    var v = vertextList[i];
                    //    vrx.AddVertex(new VertexC4V3f(color_int, (float)v.m_X, (float)v.m_Y));
                    //}
                    ////-------------------------------------
                    //GL.EnableClientState(ArrayCap.ColorArray);
                    //GL.EnableClientState(ArrayCap.VertexArray);
                    //int pcount = vrx.Count;
                    //vbo.BindBuffer();
                    //DrawTrianglesWithVertexBuffer(vrx, pcount);
                    //vbo.UnbindBuffer();
                    //GL.DisableClientState(ArrayCap.ColorArray);
                    //GL.DisableClientState(ArrayCap.VertexArray);
                    ////--------------------------------------
                }
                break;
                }
            }
            break;
            }
        }
 static void AddVertext(ArrayList<float> vrx, float f0, float f1, float f2)
 {
     vrx.AddVertex(f0);
     vrx.AddVertex(f1);
     vrx.AddVertex(f2);
 }
Example #9
0
 static void AddVertext(ArrayList <float> vrx, float f0, float f1, float f2)
 {
     vrx.AddVertex(f0);
     vrx.AddVertex(f1);
     vrx.AddVertex(f2);
 }