Ejemplo n.º 1
0
        public void Render(float[] v2fArray, float cx, float cy, float r, PixelFarm.CpuBlit.VertexProcessing.Affine invertedAffineTx, GLBitmap lookupBmp)
        {
            SetCurrent();
            CheckViewMatrix();
            //----------------------------------------------------
            a_position.LoadPureV2f(v2fArray);
            u_center.SetValue(cx + _orthov_offsetX, cy - _orthov_offsetY, r);
            UploadGradientLookupTable(lookupBmp);

            if (invertedAffineTx != null)
            {
                float[] mat3x3 = invertedAffineTx.Get3x3MatrixElements();
                u_invertedTxMatrix.SetData(mat3x3);
                _isIdenMatrixLoaded = false;
            }
            else
            {
                //identity mat
                if (!_isIdenMatrixLoaded)
                {
                    u_invertedTxMatrix.SetData(s_mat3x3Identity);
                    _isIdenMatrixLoaded = true;
                }
            }
            GL.DrawArrays(BeginMode.Triangles, 0, v2fArray.Length / 2);
        }
Ejemplo n.º 2
0
        public override void Init()
        {
            VgVisualElement renderVx    = VgVisualDocHelper.CreateVgVisualDocFromFile(@"Samples\lion.svg").VgRootElem;
            var             spriteShape = new SpriteShape(renderVx);

            _testSprite = new MyTestSprite(spriteShape);

            //lionFill.AutoFlipY = true;

            _currentTx = PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix(
                VertexProcessing.AffinePlan.RotateDeg(30),
                VertexProcessing.AffinePlan.Scale(2)
                );
        }
Ejemplo n.º 3
0
        //
        void SetupCorner_Controller(UIControllerBox box)
        {
            Color c = KnownColors.FromKnownColor(KnownColor.Orange);

            box.BackColor = c;// new Color(200, c.R, c.G, c.B);
            box.SetLocation(200, 200);
            box.Visible = true;

            box.MouseDrag += (s, e) =>
            {
                Point  pos = box.Position;
                double x1  = pos.X;
                double y1  = pos.Y;

                if (firstTime)
                {
                    _mouseDownX = x1;
                    _mouseDownY = y1;
                    firstTime   = false;
                    //find rad of firsttime
                    _firstTimeRad    = Math.Atan2(y1, x1);
                    _rotateAngleDiff = 0;
                }
                else
                {
                    double newX = _actualX + e.XDiff;
                    double newY = _actualY + e.YDiff;

                    //find new angle
                    double thisTimeRad = Math.Atan2(newY, newX);
                    _rotateAngleDiff = thisTimeRad - _firstTimeRad;

                    x1 = _mouseDownX; //prevent rounding error
                    y1 = _mouseDownY; //prevent rounding error
                }
                //if (firstTime)
                //{
                //    _snapX1 = x1;
                //    _snapY1 = y1;
                //    firstTime = false;
                //}
                //else
                //{
                //    x1 = _snapX1;
                //    y1 = _snapY1;
                //}
                //double current_distance = Math.Sqrt(x1 * x1 + y1 * y1);

                //
                //double newX = pos.X + e.XDiff;
                //double newY = pos.Y + e.YDiff;

                //float diff = 1;

                //if (e.XDiff > 0)
                //{
                //    diff = -1;
                //}

                //box.SetLocation((int)newX, (int)newY);
                PixelFarm.CpuBlit.VertexProcessing.Affine aff = PixelFarm.CpuBlit.VertexProcessing.Affine.New(
                    //PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-x1, -y1),
                    PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Rotate(_rotateAngleDiff));

                //PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(x1, y1));

                aff.Transform(ref x1, ref y1);
                _actualX = x1;
                _actualY = y1;

                box.SetLocation((int)Math.Round(x1), (int)Math.Round(y1)); //essential to use double, prevent rounding err ***



                //var targetBox = box.TargetBox;

                ////test rotation around some axis
                ////find box center
                //if (targetBox != null)
                //{
                //    //find box center
                //    float centerX = (float)((targetBox.Width + targetBox.Left) / 2f);
                //    float centerY = (float)((targetBox.Height + targetBox.Top) / 2f);
                //    //
                //    Double angle = Math.Atan2(newY - centerY, newX - centerX);
                //    //rotate
                //    PixelFarm.CpuBlit.VertexProcessing.Affine aff = PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix(
                //       PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-targetBox.Width / 2, -targetBox.Height / 2),
                //       PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Rotate(angle),
                //       PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(targetBox.Width / 2, targetBox.Height / 2)
                //    );
                //    //transform
                //    aff.Transform(ref x1, ref y1);
                //    box.SetLocation((int)x1, (int)y1);

                //}

                //if (targetBox != null)
                //{
                //    //move target box too
                //    targetBox.SetLocation(newX + 5, newY + 5);
                //}

                e.CancelBubbling = true;
            };
            _controls.Add(box);
        }
Ejemplo n.º 4
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.Clear(PixelFarm.Drawing.Color.White); //set clear color and clear all buffer
            _pcx.ClearColorBuffer();                   //test , clear only color buffer
            //-------------------------------
            if (!_isInit)
            {
                _glbmp  = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg");
                _isInit = true;
            }

            PixelFarm.Drawing.RenderSurfaceOrientation prevOrgKind = _pcx.OriginKind; //save
            switch (DrawSet)
            {
            default:
            case T107_1_DrawImageSet.Full:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImage(_glbmp, i, i);         //left,top (NOT x,y)
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImage(_glbmp, i, i);         //left,top (NOT x,y)
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.Half:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);         //left,top (NOT x,y)
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToRect:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    //PixelFarm.Drawing.RectangleF srcRect = new PixelFarm.Drawing.RectangleF(i, i, _glbmp.Width, _glbmp.Height);
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    //PixelFarm.Drawing.RectangleF srcRect = new PixelFarm.Drawing.RectangleF(i, i, _glbmp.Width, _glbmp.Height);
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToQuad1:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageToQuad(_glbmp,
                                         new PixelFarm.Drawing.PointF(i, i),
                                         new PixelFarm.Drawing.PointF(i + _glbmp.Width / 2, i),
                                         new PixelFarm.Drawing.PointF(i + _glbmp.Width / 2, i + _glbmp.Height / 2),
                                         new PixelFarm.Drawing.PointF(i, i + _glbmp.Height / 2));

                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageToQuad(_glbmp,
                                         new PixelFarm.Drawing.PointF(i, i),
                                         new PixelFarm.Drawing.PointF(i + _glbmp.Width / 2, i),
                                         new PixelFarm.Drawing.PointF(i + _glbmp.Width / 2, i + _glbmp.Height / 2),
                                         new PixelFarm.Drawing.PointF(i, i + _glbmp.Height / 2));

                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToQuad2:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;

                float rotateDegree = 20;

                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    float[] quad = new float[]
                    {
                        0, 0,                        //left-top
                        _glbmp.Width, 0,             //right-top
                        _glbmp.Width, _glbmp.Height, //right-bottom
                        0, _glbmp.Height             //left bottom
                    };

                    PixelFarm.CpuBlit.VertexProcessing.Affine aff =
                        PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix2(
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.RotateDeg(rotateDegree),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2));


                    aff.Transform(ref quad[0], ref quad[1]);
                    aff.Transform(ref quad[2], ref quad[3]);
                    aff.Transform(ref quad[4], ref quad[5]);
                    aff.Transform(ref quad[6], ref quad[7]);


                    _pcx.DrawImageToQuad(_glbmp,
                                         new PixelFarm.Drawing.PointF(quad[0], quad[1]),
                                         new PixelFarm.Drawing.PointF(quad[2], quad[3]),
                                         new PixelFarm.Drawing.PointF(quad[4], quad[5]),
                                         new PixelFarm.Drawing.PointF(quad[6], quad[7]));

                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    float[] quad = new float[]
                    {
                        0, 0,                         //left-top
                        _glbmp.Width, 0,              //right-top
                        _glbmp.Width, -_glbmp.Height, //right-bottom
                        0, -_glbmp.Height             //left bottom
                    };

                    PixelFarm.CpuBlit.VertexProcessing.Affine aff =
                        PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix2(
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.RotateDeg(rotateDegree),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2));


                    aff.Transform(ref quad[0], ref quad[1]);
                    aff.Transform(ref quad[2], ref quad[3]);
                    aff.Transform(ref quad[4], ref quad[5]);
                    aff.Transform(ref quad[6], ref quad[7]);


                    _pcx.DrawImageToQuad(_glbmp,
                                         new PixelFarm.Drawing.PointF(quad[0], quad[1]),
                                         new PixelFarm.Drawing.PointF(quad[2], quad[3]),
                                         new PixelFarm.Drawing.PointF(quad[4], quad[5]),
                                         new PixelFarm.Drawing.PointF(quad[6], quad[7]));


                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToQuad3:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;

                float rotateDegree = 60;

                for (int i = 0; i < 400;)
                {
                    PixelFarm.CpuBlit.VertexProcessing.Affine aff =
                        PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix2(
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.RotateDeg(rotateDegree),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2));

                    _pcx.DrawImageToQuad(_glbmp, aff);


                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    PixelFarm.CpuBlit.VertexProcessing.Affine aff =
                        PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix2(
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.RotateDeg(rotateDegree),
                            PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2));

                    _pcx.DrawImageToQuad(_glbmp, aff);


                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImages0:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(0, 0, _glbmp.Width, _glbmp.Height);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(0, 0, _glbmp.Width, _glbmp.Height);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImages1:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(0, 0, _glbmp.Width / 2, _glbmp.Height / 2);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(0, 0, _glbmp.Width / 2, _glbmp.Height / 2);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImages2:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(20, 20, 50, 50);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(20, 20, 50, 50);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImagesWithScale:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(20, 20, 50, 50);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i, 2f);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(20, 20, 50, 50);
                    _pcx.DrawSubImage(_glbmp, ref srcRect, i, i, 2f);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImageWithBlurX:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageWithBlurX(_glbmp, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageWithBlurX(_glbmp, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImageWithBlurY:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageWithBlurY(_glbmp, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageWithBlurY(_glbmp, i, i);
                    i += 50;
                }

                //
            }
            break;

            case T107_1_DrawImageSet.DrawWithConv3x3:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageWithConv3x3(_glbmp, Mat3x3ConvGen.sobelHorizontal, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageWithConv3x3(_glbmp, Mat3x3ConvGen.emboss, i, i);
                    i += 50;
                }
            }
            break;
            }
            _pcx.OriginKind = prevOrgKind;//restore
        }