Пример #1
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  = ConvertFromBGRA_To_RGBA(DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg"));
                _isInit = true;
            }

            PixelFarm.Drawing.RenderSurfaceOrientation prevOrgKind = _pcx.OriginKind; //save
            _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;

            _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
            //_pcx.DrawFrameBuffer(_frameBuffer, 0, 0, true);
            for (int i = 0; i < 1; ++i)
            {
                _pcx.DrawImage(_glbmp, 100 + (i * 30), 200 + (i * 30));
            }

            //-------------------------------
            _pcx.OriginKind = prevOrgKind;//restore
        }
Пример #2
0
        GLBitmap ConvertFromBGRA_To_RGBA(GLBitmap bgraBmp)
        {
            GLBitmap rgba_result = new GLBitmap(bgraBmp.Width, bgraBmp.Height);//create another from blank with the same size

            using (GLRenderSurface surface1 = new GLRenderSurface(bgraBmp.Width, bgraBmp.Height))
                using (GLRenderSurface surface2 = new GLRenderSurface(rgba_result, false))
                {
                    _pcx.AttachToRenderSurface(surface1);
                    _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                    //------------------------------------------------------------------------------------
                    //after make the frameBuffer current
                    //then all drawing command will apply to frameBuffer
                    //do draw to frame buffer here
                    _pcx.Clear(PixelFarm.Drawing.Color.Black);
                    _pcx.DrawImage(bgraBmp, 0, 0);
                    //------------------------------------------------------------------------------------
                    _pcx.AttachToRenderSurface(null);
                    //after release current, we move back to default frame buffer again***

                    _pcx.AttachToRenderSurface(surface2);
                    _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                    _pcx.Clear(PixelFarm.Drawing.Color.Black);
                    _pcx.DrawImage(surface1.GetGLBitmap(), 0, 0);
                    _pcx.AttachToRenderSurface(null);
                }
            return(rgba_result);
        }
Пример #3
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.ClearColorBuffer();
            _painter.FillColor = PixelFarm.Drawing.Color.Black;
            _painter.FillRect(0, 0, 150, 150);
            GLBitmap glBmp        = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg");
            var      textureBrush = new TextureBrush(glBmp);

            _painter.FillRenderVx(textureBrush, _polygon1);
            //-------------------------------------------------------------------------
            var linearGrBrush2 = new LinearGradientBrush(
                new PointF(0, 50), new PointF(0, 100),
                Color.Red, Color.White);

            //fill polygon with gradient brush
            _painter.FillColor = Color.Yellow;
            _painter.FillRect(200, 0, 150, 150);
            _painter.FillRenderVx(linearGrBrush2, _polygon2);
            _painter.FillColor = Color.Black;
            _painter.FillRect(400, 0, 150, 150);
            //-------------------------------------------------------------------------
            //another  ...
            _painter.FillRenderVx(linearGrBrush2, _polygon3);
            //-------------------------------------------------------------------------


            SwapBuffers();
        }
Пример #4
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            canvas2d.SmoothMode  = CanvasSmoothMode.Smooth;
            canvas2d.StrokeColor = PixelFarm.Drawing.Color.Blue;
            canvas2d.ClearColorBuffer();
            painter.FillColor = PixelFarm.Drawing.Color.Black;
            painter.FillRectLBWH(0, 0, 150, 150);
            GLBitmap glBmp        = LoadTexture(RootDemoPath.Path + "\\logo-dark.jpg");
            var      textureBrush = new TextureBrush(glBmp);

            painter.FillRenderVx(textureBrush, polygon1);
            //-------------------------------------------------------------------------
            var linearGrBrush2 = new LinearGradientBrush(
                new PointF(0, 50), Color.Red,
                new PointF(400, 100), Color.White);

            //fill polygon with gradient brush
            painter.FillColor = Color.Yellow;
            painter.FillRectLBWH(200, 0, 150, 150);
            painter.FillRenderVx(linearGrBrush2, polygon2);
            painter.FillColor = Color.Black;
            painter.FillRectLBWH(400, 0, 150, 150);
            //-------------------------------------------------------------------------

            //another  ...

            painter.FillRenderVx(linearGrBrush2, polygon3);
            //-------------------------------------------------------------------------


            SwapBuffer();
        }
Пример #5
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            canvas2d.SmoothMode  = CanvasSmoothMode.Smooth;
            canvas2d.StrokeColor = PixelFarm.Drawing.Color.Blue;
            canvas2d.ClearColorBuffer();
            if (!resInit)
            {
                msdf_bmp = LoadTexture(RootDemoPath.Path + @"\msdf_75.png");
                //msdf_bmp = LoadTexture(@"d:\\WImageTest\\a001_x1.png");
                //msdf_bmp = LoadTexture(@"d:\\WImageTest\\msdf_65.png");
                resInit = true;
            }
            canvas2d.Clear(PixelFarm.Drawing.Color.White);

            //canvas2d.DrawImageWithMsdf(msdf_bmp, 0, 400, 6);
            //canvas2d.DrawImageWithMsdf(msdf_bmp, 100, 500, 0.5f);
            //canvas2d.DrawImageWithMsdf(msdf_bmp, 100, 520, 0.4f);
            //canvas2d.DrawImageWithMsdf(msdf_bmp, 100, 550, 0.3f);
            //canvas2d.DrawImage(msdf_bmp, 150, 400);

            canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 200, 500, 15f);
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 300, 500, 0.5f);
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 300, 520, 0.4f);
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 300, 550, 0.3f);

            ////
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 400, 6);
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 500, 0.5f);
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 520, 0.4f);
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 550, 0.3f);
            canvas2d.DrawImage(msdf_bmp, 100, 300);

            miniGLControl.SwapBuffers();
        }
        public override void BlitFrom(DrawBoard src, float srcX, float srcY, float srcW, float srcH, float dstX, float dstY)
        {
            if (!src.IsGpuDrawBoard)
            {
                //cpu draw board
                BitmapBufferProvider bmpProvider = src.GetInternalBitmapProvider();

                if (_tmpGLBmp == null)
                {
                    _tmpGLBmp = new GLBitmap(bmpProvider);
                }
                else
                {
                    _tmpGLBmp.UpdateTexture(new Rectangle((int)srcX, (int)srcY, (int)srcW, (int)srcH));
                }

                //---------
                this.DrawImage(_tmpGLBmp,
                               new RectangleF((int)dstX, (int)dstY, (int)srcW, (int)srcH),  //dst
                               new RectangleF((int)srcX, (int)srcY, (int)srcW, (int)srcH)); //src
            }
            else
            {
                //TODO: implement this....
            }
        }
Пример #7
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.ClearColorBuffer();
            if (!_resInit)
            {
                _msdf_bmp = DemoHelper.LoadTexture(RootDemoPath.Path + @"\msdf_75.png");
                _resInit  = true;
            }
            _pcx.Clear(PixelFarm.Drawing.Color.White);

            //canvas2d.DrawImageWithMsdf(msdf_bmp, 0, 400, 6);
            //canvas2d.DrawImageWithMsdf(msdf_bmp, 100, 500, 0.5f);
            //canvas2d.DrawImageWithMsdf(msdf_bmp, 100, 520, 0.4f);
            //canvas2d.DrawImageWithMsdf(msdf_bmp, 100, 550, 0.3f);
            //canvas2d.DrawImage(msdf_bmp, 150, 400);

            //_pcx.draw(_msdf_bmp, 200, 500, 15f, );
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 300, 500, 0.5f);
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 300, 520, 0.4f);
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 300, 550, 0.3f);

            _pcx.DrawImageWithMsdf(_msdf_bmp, 300, 500, 0.5f, PixelFarm.Drawing.Color.Black);
            ////
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 400, 6);
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 500, 0.5f);
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 520, 0.4f);
            //canvas2d.DrawImageWithMsdf(sdf_bmp, 400, 550, 0.3f);
            _pcx.DrawImage(_msdf_bmp, 100, 300);

            SwapBuffers();
        }
Пример #8
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.ClearColorBuffer();
            if (!_resInit)
            {
                _msdf_bmp = DemoHelper.LoadTexture(_fontAtlas.MainBitmap);
                _resInit  = true;
            }

            _painter.Clear(PixelFarm.Drawing.Color.White);


            _fontAtlas.TryGetItem(_glyphIndex_0, out AtlasItem glyphData);
            PixelFarm.Drawing.Rectangle r =
                new PixelFarm.Drawing.Rectangle(glyphData.Left,
                                                glyphData.Top,
                                                glyphData.Width,
                                                glyphData.Height);

            _pcx.DrawSubImageWithMsdf(_msdf_bmp, ref r, 100, 40);

            _fontAtlas.TryGetItem(_glyphIndex_1, out glyphData);
            PixelFarm.Drawing.Rectangle r2 = new PixelFarm.Drawing.Rectangle(glyphData.Left,
                                                                             glyphData.Top,
                                                                             glyphData.Width,
                                                                             glyphData.Height);
            _pcx.DrawSubImageWithMsdf(_msdf_bmp, ref r2, 100 + r.Width, 40);

            //full image
            _pcx.DrawImage(_msdf_bmp, 0, 100);
            SwapBuffers();
        }
Пример #9
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            //1. create color bmp
            _colorBmp = new MemBitmap(100, 100);
            using (Tools.BorrowAggPainter(_colorBmp, out var painter))
            {
                painter.Clear(Color.White);
                painter.FillRect(2, 2, 80, 80, Color.Red);
            }
            //2. create mask bmp

            using (Tools.BorrowEllipse(out var ellipse))
                using (Tools.BorrowVxs(out var v1, out var v2))
                {
                    var msdf = new Msdfgen.MsdfGen3();

                    v1.AddMoveTo(0, 0);
                    v1.AddLineTo(20, 0);
                    v1.AddLineTo(10, 15);
                    v1.AddCloseFigure();

                    v1.ScaleToNewVxs(1, -1, v2); //flipY

                    //msdf.MsdfGenParams = new Msdfgen.MsdfGenParams() { UseCustomImageSize = true, CustomWidth = 64, CustomHeight = 64 };
                    BitmapAtlasItemSource itemSrc = msdf.GenerateMsdfTexture(v2);
                    _msdfMaskBmp = MemBitmap.CreateFromCopy(itemSrc.Width, itemSrc.Height, itemSrc.Source);
#if DEBUG
                    //_msdfMaskBmp.SaveImage("mask_msdf.png");
#endif
                }
            _colorGLBmp    = new GLBitmap(_colorBmp);
            _msdfMaskGLBmp = new GLBitmap(_msdfMaskBmp);
        }
 public GLBitmapReference(GLBitmap ownerBmp, int x, int y, int w, int h)
 {
     this.Left     = x;
     this.Top      = y;
     this.Width    = w;
     this.Height   = h;
     this.ownerBmp = ownerBmp;
 }
Пример #11
0
 protected override void OnDispose()
 {
     if (innerGLbmp != null)
     {
         innerGLbmp.Dispose();
         innerGLbmp = null;
     }
 }
Пример #12
0
 public GLBitmapReference(GLBitmap ownerBmp, int x, int y, int w, int h)
 {
     this.Left = x;
     this.Top = y;
     this.Width = w;
     this.Height = h;
     this.ownerBmp = ownerBmp;
 }
 public override void Dispose()
 {
     //TODO: review here
     if (_tmpGLBmp != null)
     {
         _tmpGLBmp.Dispose();
         _tmpGLBmp = null;
     }
 }
Пример #14
0
        public override void Load()
        {
            //-----------------------------------------------
            FormTestWinGLControl form   = new FormTestWinGLControl();
            CanvasGL2d           canvas = new CanvasGL2d(this.Width, this.Height);
            var lionFill = new LionFillSprite();
            //-----------------------------------------------

            GLBitmap bmp1 = null;
            int      bmpW = 0;
            int      bmpH = 0;

            form.SetGLPaintHandler((o, s) =>
            {
                canvas.Clear(PixelFarm.Drawing.Color.White);

                //since OpenGL < 3 dose not have FrameBuffer
                //so we first draw it to backbuffer
                //then copy data from back buffer to texture
                if (bmp1 == null)
                {
                    lionFill.Draw(canvas);

                    GL.ReadBuffer(ReadBufferMode.Back);
                    Bitmap bmp           = new Bitmap(800, 600, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    byte[] buffer_output = new byte[800 * 4 * 600];
                    var bmpdata          = bmp.LockBits(
                        new Rectangle(0, 0, 800, 600),
                        System.Drawing.Imaging.ImageLockMode.ReadWrite,
                        bmp.PixelFormat);
                    GL.ReadPixels(0, 0, 800, 600, PixelFormat.Bgra, PixelType.Byte, bmpdata.Scan0);
                    unsafe
                    {
                        fixed(byte *outputH = &buffer_output[0])
                        {
                            GL.ReadPixels(0, 0, 800, 600, PixelFormat.Bgra, PixelType.Byte, (IntPtr)outputH);
                        }
                    }
                    bmp.UnlockBits(bmpdata);
                    //save
                    bmp.Save("d:\\WImageTest\\glLion.png");
                    //---------
                    //canvas.DrawImage(GLBitmapTexture.CreateBitmapTexture(bmp), 0, 0, bmp.Width, bmp.Height);
                    bmp1 = PixelFarm.Drawing.DrawingGL.GLBitmapTextureHelper.CreateBitmapTexture(bmp);
                    bmpW = bmp.Width;
                    bmpH = bmp.Height;

                    canvas.Clear(PixelFarm.Drawing.Color.White);
                }
                canvas.DrawImage(bmp1, 0, 0, bmpW, bmpH);

                //canvas.Clear(PixelFarm.Drawing.Color.White);
            });
            form.Show();
        }
Пример #15
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);
            _pcx.ClearColorBuffer();
            //-------------------------------
            _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
            if (!_isInit)
            {
                _glbmp  = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.png");
                _isInit = true;
            }
            if (_surface1.IsValid)
            {
                if (_frameBufferNeedUpdate)
                {
                    //------------------------------------------------------------------------------------
                    //framebuffer
                    _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                    _pcx.AttachToRenderSurface(_surface1);
                    //after make the frameBuffer current
                    //then all drawing command will apply to frameBuffer
                    //do draw to frame buffer here
                    _pcx.Clear(PixelFarm.Drawing.Color.Red);
                    _pcx.DrawImageWithBlurX(_glbmp, 0, 0);
                    _pcx.AttachToRenderSurface(null);//switch to primary render surface
                    //------------------------------------------------------------------------------------
                    //framebuffer2

                    _pcx.AttachToRenderSurface(_surface2);
                    _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;

                    //GLBitmap bmp2 = new GLBitmap(_frameBuffer.TextureId, _frameBuffer.Width, _frameBuffer.Height);
                    //bmp2.IsYFlipped = true;
                    //bmp2.IsBigEndianPixel = true;

                    _pcx.DrawImageWithBlurY(_surface1.GetGLBitmap(), 0, 0);
                    _pcx.AttachToRenderSurface(null);
                    //------------------------------------------------------------------------------------
                    //after release current, we move back to default frame buffer again***
                    _frameBufferNeedUpdate = false;
                }
                _pcx.DrawImage(_surface2.GetGLBitmap(), 0, 0);

                //_pcx.DrawFrameBuffer(_frameBuffer2, 0, 0, true);
            }
            else
            {
                _pcx.Clear(PixelFarm.Drawing.Color.Blue);
            }
            //-------------------------------
            SwapBuffers();
        }
Пример #16
0
        protected virtual bool HasSomeExtension => false;//class that override

        public void CreatePrimaryRenderElement(GLPainterContext pcx, GLPainter painter, RootGraphic rootgfx)
        {
            if (_canvasRenderE == null)
            {
                var glBmp = new GLBitmap(_memBitmapBinder);
                glBmp.IsYFlipped = false;
                //
                var glRenderElem = new CpuBlitGLCanvasRenderElement(rootgfx, _width, _height, glBmp);
                glRenderElem.SetController(this); //connect to event system
                glRenderElem.SetOwnerDemoUI(this);
                _canvasRenderE = glRenderElem;
            }
        }
Пример #17
0
        protected override void OnGLPainterReady(GLPainter painter)
        {
            _pcx     = painter.Core;
            _painter = painter;
            _glBmp   = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg");
            _glBmp2  = DemoHelper.LoadTexture(RootDemoPath.Path + @"\lion1_v2.png");

            _textureBrush  = new TextureBrush(_glBmp);
            _textureBrush2 = new TextureBrush(_glBmp2);

            _linearGradient = new LinearGradientBrush(
                new PointF(10, 50), new PointF(10, 100),
                Color.Red, Color.White);
        }
Пример #18
0
        static void UpdateViewContent(FormRenderUpdateEventArgs formRenderUpdateEventArgs)
        {
            needUpdateContent = false;
            //1. create platform bitmap
            // create the surface
            int w = 800;
            int h = 600;

            if (myImg == null)
            {
                myImg = new TestGlfw.MyNativeRGBA32BitsImage(w, h);
            }


            int testNo = 2;

            if (testNo == 0)
            {
                //test1
                // create the surface
                var info = new SKImageInfo(w, h, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
                using (var surface = SKSurface.Create(info, myImg.Scan0, myImg.Stride))
                {
                    // start drawing
                    SKCanvas canvas = surface.Canvas;
                    DrawWithSkia(canvas);
                    surface.Canvas.Flush();
                }
                glBmp = new PixelFarm.DrawingGL.GLBitmap(w, h, myImg.Scan0);
            }
            else
            {
                ////---------------------------------------------------------------------------------------
                //test2
                var lionShape = new PixelFarm.Agg.SpriteShape();
                lionShape.ParseLion();
                var lionBounds = lionShape.Bounds;
                //-------------
                var aggImage   = new PixelFarm.Agg.ActualImage((int)lionBounds.Width, (int)lionBounds.Height, PixelFarm.Agg.PixelFormat.ARGB32);
                var imgGfx2d   = new PixelFarm.Agg.ImageGraphics2D(aggImage);
                var aggPainter = new PixelFarm.Agg.AggCanvasPainter(imgGfx2d);
                DrawLion(aggPainter, lionShape, lionShape.Path.Vxs);
                //-------------



                //convert affImage to texture
                glBmp = LoadTexture(aggImage);
            }
        }
Пример #19
0
        public override void Load()
        {
            //lion fill test
            FormTestWinGLControl form   = new FormTestWinGLControl();
            CanvasGL2d           canvas = new CanvasGL2d(this.Width, this.Height);
            var lionFill = new LionFillSprite();
            //----------
            //draw lion on software layer
            ActualImage actualImage = new ActualImage(800, 600, PixelFarm.Agg.Image.PixelFormat.Rgba32);
            Graphics2D  g2d         = Graphics2D.CreateFromImage(actualImage);
            GLBitmap    bmp         = null;

            form.SetGLPaintHandler((o, s) =>
            {
                canvas.Clear(PixelFarm.Drawing.Color.White);
                //-------------------------------------
                // draw lion from bitmap to GL screen
                if (bmp == null)
                {
                    lionFill.OnDraw(g2d);
                    bmp = new GLBitmap(new LazyAggBitmapBufferProvider(actualImage));
                }
                //lion is inverted from software layer ,
                //so... we use DrawImageInvert()
                int xpos = 0;
                int w    = bmp.Width;
                int h    = bmp.Height;

                for (int i = 0; i < 3; ++i)
                {
                    canvas.DrawImage(bmp, xpos, 50, w, h);
                    w     = (int)(w * 1.2);
                    h     = (int)(h * 1.2);
                    xpos += 150;
                }
                w    = bmp.Width;
                h    = bmp.Height;
                xpos = 0;
                for (int i = 0; i < 2; ++i)
                {
                    w     = (int)(w * 0.75);
                    h     = (int)(h * 0.75);
                    xpos -= 50;
                    canvas.DrawImage(bmp, xpos, 50, w, h);
                }
            });

            form.Show();
        }
Пример #20
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
            _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;

            if (_surface1.IsValid)
            {
                if (_frameBufferNeedUpdate)
                {
                    _pcx.AttachToRenderSurface(_surface1);

                    _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                    //------------------------------------------------------------------------------------
                    //after make the frameBuffer current
                    //then all drawing command will apply to frameBuffer
                    //do draw to frame buffer here
                    _pcx.Clear(PixelFarm.Drawing.Color.Black);
                    _pcx.DrawImage(_glbmp, 5, 5);
                    //------------------------------------------------------------------------------------
                    _pcx.AttachToRenderSurface(null);
                    //after release current, we move back to default frame buffer again***
                    _frameBufferNeedUpdate = false;
                }
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftTop;
                //_pcx.DrawFrameBuffer(_frameBuffer, 0, 0, true);

                for (int i = 0; i < 1; ++i)
                {
                    _pcx.DrawImage(_surface1.GetGLBitmap(), 100 + (i * 30), 200 + (i * 30));
                }
            }
            else
            {
                _pcx.Clear(PixelFarm.Drawing.Color.Blue);
            }
            //-------------------------------
            _pcx.OriginKind = prevOrgKind;//restore
        }
Пример #21
0
        public void Print(PixelFarm.Drawing.Color color, char[] buffer, int start, int len, double x, double y)
        {
            if (this.currentFont.IsAtlasFont)
            {
                //temp hard-code here!
                PixelFarm.Agg.Fonts.GdiTextureFont textureFont = (PixelFarm.Agg.Fonts.GdiTextureFont)currentFont;
                var srcAndDestList = textureFont.GetGlyphPos(buffer, start, len, (int)x, (int)y);
                //***
                canvas2d.DrawGlyphImages(color, textureFont.BmpBoard, srcAndDestList);
            }
            else
            {
                int j        = len;
                int buffsize = j * 2;
                //get kerning list
                if (properGlyphs == null)
                {
                    properGlyphs = new ProperGlyph[buffsize];
                    currentFont.GetGlyphPos(buffer, start, buffsize, properGlyphs);
                }

                double xpos = x;
                for (int i = 0; i < buffsize; ++i)
                {
                    uint codepoint = properGlyphs[i].codepoint;
                    if (codepoint == 0)
                    {
                        break;
                    }

                    //-------------------------------------------------------------
                    FontGlyph glyph = this.currentFont.GetGlyphByIndex(codepoint);
                    //glyph image32
                    //-------------------------------------------------------------
                    GLBitmap bmp  = new GLBitmap(new LazyAggBitmapBufferProvider(glyph.glyphImage32));
                    var      left = glyph.exportGlyph.img_horiBearingX;
                    this.canvas2d.DrawImage(bmp,
                                            (float)(xpos + (left >> 6)),
                                            (float)(y + (glyph.exportGlyph.bboxYmin >> 6)));

                    int w = (glyph.exportGlyph.advanceX) >> 6;
                    xpos += (w);

                    bmp.Dispose(); //temp here
                    //-------------------------------------------------------------
                }
            }
        }
        protected override void OnReadyForInitGLShaderProgram()
        {
            lionShape = new SpriteShape();
            lionShape.ParseLion();
            RectD lionBounds = lionShape.Bounds;

            //-------------
            aggImage   = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height, PixelFarm.Agg.PixelFormat.ARGB32);
            _aggsx     = new AggRenderSurface(aggImage);
            aggPainter = new AggPainter(_aggsx);


            DrawLion(aggPainter, lionShape, lionShape.Vxs);
            //convert affImage to texture
            glBmp = DemoHelper.LoadTexture(aggImage);
        }
Пример #23
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            PaintLab.Svg.VgVisualDoc vgVisualDoc = PaintLab.Svg.VgVisualDocHelper.CreateVgVisualDocFromFile("Samples/lion.svg");
            _lionShape = new SpriteShape(vgVisualDoc.VgRootElem);

            var lionBounds = _lionShape.Bounds;

            //-------------
            _memBmp     = new MemBitmap((int)lionBounds.Width, (int)lionBounds.Height);
            _aggPainter = AggPainter.Create(_memBmp);


            DrawLion(_aggPainter, _lionShape);
            //convert affImage to texture
            _glBmp = DemoHelper.LoadTexture(_memBmp);
        }
Пример #24
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            canvas2d.SmoothMode  = CanvasSmoothMode.Smooth;
            canvas2d.StrokeColor = PixelFarm.Drawing.Color.Blue;
            canvas2d.ClearColorBuffer();
            if (!resInit)
            {
                //glbmp = LoadTexture(@"..\logo-dark.jpg");
                glbmp   = LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg");
                resInit = true;
            }

            canvas2d.DrawSubImage(glbmp, 10, 10, 100, 100, 200, 400);
            canvas2d.DrawImage(glbmp, 0, 300);
            canvas2d.DrawImageWithBlurX(glbmp, 0, 600);
            miniGLControl.SwapBuffers();
        }
 protected override void OnGLRender(object sender, EventArgs args)
 {
     _glsx.SmoothMode  = SmoothMode.Smooth;
     _glsx.StrokeColor = PixelFarm.Drawing.Color.Blue;
     _glsx.Clear(PixelFarm.Drawing.Color.White);
     _glsx.ClearColorBuffer();
     //-------------------------------
     if (!isInit)
     {
         glbmp  = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.png");
         isInit = true;
     }
     if (frameBuffer.FrameBufferId > 0)
     {
         if (frameBufferNeedUpdate)
         {
             //------------------------------------------------------------------------------------
             //framebuffer
             _glsx.AttachFrameBuffer(frameBuffer);
             //after make the frameBuffer current
             //then all drawing command will apply to frameBuffer
             //do draw to frame buffer here
             _glsx.Clear(PixelFarm.Drawing.Color.Red);
             _glsx.DrawImageWithBlurX(glbmp, 0, 300);
             _glsx.DetachFrameBuffer();
             //------------------------------------------------------------------------------------
             //framebuffer2
             _glsx.AttachFrameBuffer(frameBuffer2);
             GLBitmap bmp2 = new GLBitmap(frameBuffer.TextureId, frameBuffer.Width, frameBuffer.Height);
             bmp2.IsBigEndianPixel = true;
             _glsx.DrawImageWithBlurY(bmp2, 0, 300);
             _glsx.DetachFrameBuffer();
             //------------------------------------------------------------------------------------
             //after release current, we move back to default frame buffer again***
             frameBufferNeedUpdate = false;
         }
         _glsx.DrawFrameBuffer(frameBuffer2, 15, 300);
     }
     else
     {
         _glsx.Clear(PixelFarm.Drawing.Color.Blue);
     }
     //-------------------------------
     SwapBuffers();
 }
Пример #26
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.Clear();
            //-------------------------------
            if (!_isInit)
            {
                _isInit = true;
            }
            if (_surface1.IsValid)
            {
                GLRenderSurface.InnerGLData innerData = _surface1.GetInnerGLData();
                //------------------------------------------------------------------------------------
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, innerData.FramebufferId);
                //--------
                //do draw to frame buffer here
                GL.ClearColor(OpenTK.Graphics.Color4.Red); //clear with red color
                GL.Clear(ClearBufferMask.ColorBufferBit);


                //------------------------------------------------------------------------------------
                GL.BindTexture(TextureTarget.Texture2D, innerData.TextureId);
                GL.GenerateMipmap(TextureTarget.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, 0);
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);//switch to default framewbuffer
                //------------------------------------------------------------------------------------

                //create gl bmp from framebuffer
                GLBitmap bmp = new GLBitmap(innerData.TextureId, _surface1.Width, _surface1.Height);
                bmp.IsBigEndianPixel = true;//since this is created from FrameBuffer so set BigEndianPixel = true


                _pcx.DrawImage(bmp, 15, 0);

                //
                GL.ClearColor(OpenTK.Graphics.Color4.White); //clear with red color
            }
            else
            {
                _pcx.Clear(PixelFarm.Drawing.Color.Blue);
            }
            //-------------------------------
            SwapBuffers();
        }
Пример #27
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _glsx.SmoothMode  = SmoothMode.Smooth;
            _glsx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _glsx.ClearColorBuffer();
            if (!resInit)
            {
                //glbmp = LoadTexture(@"..\logo-dark.jpg");
                glbmp = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg");

                resInit = true;
            }

            _glsx.DrawSubImage(glbmp, 10, 10, 100, 100, 200, 400);
            _glsx.DrawImage(glbmp, 0, 300);
            _glsx.DrawImageWithBlurX(glbmp, 0, 600);
            SwapBuffers();
        }
        protected override void OnReadyForInitGLShaderProgram()
        {
            var _svgRenderVx = PixelFarm.Agg.SvgRenderVxLoader.CreateSvgRenderVxFromFile("Samples/lion.svg");

            lionShape = new SpriteShape(_svgRenderVx);

            RectD lionBounds = lionShape.Bounds;

            //-------------
            aggImage   = new ActualImage((int)lionBounds.Width, (int)lionBounds.Height);
            _aggsx     = new AggRenderSurface(aggImage);
            aggPainter = new AggPainter(_aggsx);


            DrawLion(aggPainter, lionShape);
            //convert affImage to texture
            glBmp = DemoHelper.LoadTexture(aggImage);
        }
Пример #29
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.ClearColorBuffer();
            if (!_resInit)
            {
                // msdf_bmp = LoadTexture(@"..\msdf_75.png");
                //msdf_bmp = LoadTexture(@"d:\\WImageTest\\a001_x1_66.png");
                _msdf_bmp = DemoHelper.LoadTexture(_totalBmp);
                //msdf_bmp = LoadTexture(@"d:\\WImageTest\\a001_x1.png");
                //msdf_bmp = LoadTexture(@"d:\\WImageTest\\msdf_65.png");
                _resInit = true;
            }

            _painter.Clear(PixelFarm.Drawing.Color.White);
            //var f = painter.CurrentFont;

            //painter.DrawString("hello!", 0, 20);
            //canvas2d.DrawImageWithSubPixelRenderingMsdf(msdf_bmp, 200, 500, 15f);

            Typography.Rendering.TextureGlyphMapData glyphData;

            byte[] codepoint = System.Text.Encoding.UTF8.GetBytes("AB");
            _fontAtlas.TryGetGlyphMapData(codepoint[0], out glyphData);
            PixelFarm.Drawing.Rectangle r =
                new PixelFarm.Drawing.Rectangle(glyphData.Left,
                                                glyphData.Top,
                                                glyphData.Width,
                                                glyphData.Height);
            //canvas2d.DrawSubImageWithMsdf(msdf_bmp, ref r, 100, 500);
            _pcx.DrawSubImageWithMsdf(_msdf_bmp, ref r, 100, 500);

            _fontAtlas.TryGetGlyphMapData(codepoint[1], out glyphData);
            PixelFarm.Drawing.Rectangle r2 = new PixelFarm.Drawing.Rectangle(glyphData.Left,
                                                                             glyphData.Top,
                                                                             glyphData.Width,
                                                                             glyphData.Height);
            _pcx.DrawSubImageWithMsdf(_msdf_bmp, ref r2, 100 + r.Width - 10, 500);

            //full image
            _pcx.DrawImage(_msdf_bmp, 100, 300);
            SwapBuffers();
        }
Пример #30
0
        public override void DrawImages(Image image, RectangleF[] destAndSrcPairs)
        {
            GLBitmap glBitmapTexture = image.InnerImage as GLBitmap;

            if (glBitmapTexture != null)
            {
                canvasGL2d.DrawGlyphImages(this.textColor, glBitmapTexture, destAndSrcPairs);
            }
            else
            {
                var currentInnerImage = image.InnerImage as System.Drawing.Bitmap;
                if (currentInnerImage != null)
                {
                    //create  and replace ?
                    //TODO: add to another field
                    image.InnerImage = glBitmapTexture = GLBitmapTextureHelper.CreateBitmapTexture(currentInnerImage);
                    canvasGL2d.DrawGlyphImages(this.textColor, glBitmapTexture, destAndSrcPairs);
                }
            }
        }
Пример #31
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            canvas2d.SmoothMode  = CanvasSmoothMode.Smooth;
            canvas2d.StrokeColor = PixelFarm.Drawing.Color.Blue;
            canvas2d.Clear(PixelFarm.Drawing.Color.White);
            canvas2d.ClearColorBuffer();
            //-------------------------------
            if (!isInit)
            {
                isInit = true;
            }
            if (frameBuffer.FrameBufferId > 0)
            {
                //------------------------------------------------------------------------------------
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer.FrameBufferId);
                //--------
                //do draw to frame buffer here
                GL.ClearColor(OpenTK.Graphics.Color4.Red);
                GL.Clear(ClearBufferMask.ColorBufferBit);
                //------------------------------------------------------------------------------------



                //------------------------------------------------------------------------------------
                GL.BindTexture(TextureTarget.Texture2D, frameBuffer.TextureId);
                GL.GenerateMipmap(TextureTarget.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, 0);
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                //------------------------------------------------------------------------------------

                GLBitmap bmp = new GLBitmap(frameBuffer.TextureId, frameBuffer.Width, frameBuffer.Height);
                bmp.IsBigEndianPixel = true;
                canvas2d.DrawImage(bmp, 15, 300);
            }
            else
            {
                canvas2d.Clear(PixelFarm.Drawing.Color.Blue);
            }
            //-------------------------------
            SwapBuffer();
        }