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(); }
public override void Load() { //----------------------------------------------- FormTestWinGLControl form = new FormTestWinGLControl(); CanvasGL2d canvas = new CanvasGL2d(this.Width, this.Height); var lionFill = new LionFillSprite(); //----------------------------------------------- form.SetGLPaintHandler((o, s) => { //canvas.Orientation = PixelFarm.Drawing.CanvasOrientation.LeftTop; canvas.Clear(PixelFarm.Drawing.Color.White); canvas.FillRect(PixelFarm.Drawing.Color.Blue, 0, 0, 400, 400); //draw vxs direct to GL surface //lionFill.Draw(canvas); //before offset canvas.EnableClipRect(); canvas.SetClipRectRel(200, 250, 100, 100); lionFill.Draw(canvas); //offset canvas.SetCanvasOrigin(50, 50); //test clipping canvas.SetClipRectRel(200, 250, 100, 100); lionFill.Draw(canvas); canvas.DisableClipRect(); canvas.SetCanvasOrigin(0, 0); }); form.Show(); }
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(); }
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) { glbmp = LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg"); isInit = true; } if (frameBuffer.FrameBufferId > 0) { if (frameBufferNeedUpdate) { //------------------------------------------------------------------------------------ //framebuffer canvas2d.AttachFrameBuffer(frameBuffer); //after make the frameBuffer current //then all drawing command will apply to frameBuffer //do draw to frame buffer here canvas2d.Clear(PixelFarm.Drawing.Color.Red); canvas2d.DrawImageWithBlurX(glbmp, 0, 300); canvas2d.DetachFrameBuffer(); //------------------------------------------------------------------------------------ //framebuffer2 canvas2d.AttachFrameBuffer(frameBuffer2); GLBitmap bmp2 = new GLBitmap(frameBuffer.TextureId, frameBuffer.Width, frameBuffer.Height); bmp2.IsBigEndianPixel = true; canvas2d.DrawImageWithBlurY(bmp2, 0, 300); canvas2d.DetachFrameBuffer(); //------------------------------------------------------------------------------------ //after release current, we move back to default frame buffer again*** frameBufferNeedUpdate = false; } canvas2d.DrawFrameBuffer(frameBuffer2, 15, 300); } else { canvas2d.Clear(PixelFarm.Drawing.Color.Blue); } //------------------------------- miniGLControl.SwapBuffers(); }
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(); }
public override void Load() { //draw 1 FormTestWinGLControl form = new FormTestWinGLControl(); CanvasGL2d canvas = new CanvasGL2d(this.Width, this.Height); form.SetGLPaintHandler((o, s) => { canvas.Clear(PixelFarm.Drawing.Color.White); }); form.Show(); }
protected override void OnGLRender(object sender, EventArgs args) { canvas2d.SmoothMode = CanvasSmoothMode.Smooth; canvas2d.StrokeColor = PixelFarm.Drawing.Color.Blue; canvas2d.ClearColorBuffer(); canvas2d.Clear(PixelFarm.Drawing.Color.Red); //------------------------------- painter.DrawString("OK", 0, 17); painter.DrawString("1234567890", 0, 17 * 3); //------------------------------- SwapBuffer(); }
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) { glbmp = LoadTexture(RootDemoPath.Path + @"\leaves.jpg"); isInit = true; } if (frameBuffer.FrameBufferId > 0) { if (frameBufferNeedUpdate) { //------------------------------------------------------------------------------------ //framebuffer canvas2d.AttachFrameBuffer(frameBuffer); //after make the frameBuffer current //then all drawing command will apply to frameBuffer //do draw to frame buffer here canvas2d.Clear(PixelFarm.Drawing.Color.Red); canvas2d.DrawImageWithConv3x3(glbmp, Mat3x3ConvGen.emboss, 0, 300); canvas2d.DetachFrameBuffer(); //after release current, we move back to default frame buffer again*** frameBufferNeedUpdate = false; } canvas2d.DrawFrameBuffer(frameBuffer, 15, 300); } else { canvas2d.Clear(PixelFarm.Drawing.Color.Blue); } //------------------------------- miniGLControl.SwapBuffers(); }
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(); }
public override void Load() { //----------------------------------------------- FormTestWinGLControl form = new FormTestWinGLControl(); CanvasGL2d canvas = new CanvasGL2d(this.Width, this.Height); var lionFill = new LionFillSprite(); //----------------------------------------------- form.SetGLPaintHandler((o, s) => { canvas.Clear(PixelFarm.Drawing.Color.White); canvas.FillRect(PixelFarm.Drawing.Color.Blue, 0, 0, 400, 400); //draw vxs direct to GL surface lionFill.Draw(canvas); }); form.Show(); }
public override void Load() { //draw 1 FormTestWinGLControl form = new FormTestWinGLControl(); CanvasGL2d canvas = new CanvasGL2d(this.Width, this.Height); GLBitmap hwBmp = null; form.SetGLPaintHandler((o, s) => { canvas.Clear(PixelFarm.Drawing.Color.White); canvas.StrokeColor = PixelFarm.Drawing.Color.DeepPink; var polygonCoords = new float[] { 5, 300, 40, 300, 50, 340 }; canvas.FillPolygon(PixelFarm.Drawing.Color.DeepPink, polygonCoords, 3); }); form.Show(); }
protected override void OnGLRender(object sender, EventArgs args) { canvas2d.SmoothMode = CanvasSmoothMode.Smooth; canvas2d.StrokeColor = PixelFarm.Drawing.Color.Blue; //----------------------------- //see: lazyfoo.net/tutorials/OpenGL/26_the_stencil_buffer/index.php //----------------------------- canvas2d.Clear(PixelFarm.Drawing.Color.White); //------------------- //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 painter.FillColor = PixelFarm.Drawing.Color.Black; painter.FillRenderVx(stencilPolygon); painter.StrokeColor = PixelFarm.Drawing.Color.Black; //render color GL.ColorMask(true, true, true, true); //where a 1 was not rendered GL.StencilFunc(StencilFunction.Equal, 1, 1); //keep the pixel GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep); //draw painter.FillColor = PixelFarm.Drawing.Color.Red; painter.FillRenderVx(rectPolygon); GL.Disable(EnableCap.StencilTest); //----------------------------------------------------------- SwapBuffer(); }
public override void Load() { //---------------------------------------------------- //test only TextureAtlas textureAtlas = new TextureAtlas(800, 600); int areaId, x, y; for (int i = 0; i < 100; ++i) { var result2 = textureAtlas.AllocNewRectArea(100, 200, out areaId, out x, out y); if (result2 != TextureAtlasAllocResult.Ok) { } } //---------------------------------------------------- FormTestWinGLControl form = new FormTestWinGLControl(); CanvasGL2d canvas = new CanvasGL2d(this.Width, this.Height); form.SetGLPaintHandler((o, s) => { canvas.Clear(PixelFarm.Drawing.Color.White); }); form.Show(); }
public override void Init() { FormTestWinGLControl2 form = new FormTestWinGLControl2(); CanvasGL2d canvas = new CanvasGL2d(this.Width, this.Height); GLTextPrinter glTextPrinter = new GLTextPrinter(canvas); form.SetGLPaintHandler((o, s) => { canvas.Clear(PixelFarm.Drawing.Color.White); if (hwBmp == null) { hwBmp = PixelFarm.Drawing.DrawingGL.GLBitmapTextureHelper.CreateBitmapTexture( new Bitmap("../../../Data/Textures/logo-dark.jpg")); } //canvas.DrawImage(hwBmp, 10, 10); canvas.DrawImage(hwBmp, 300, 300, hwBmp.Width / 4, hwBmp.Height / 4); canvas.StrokeColor = PixelFarm.Drawing.Color.DeepPink; canvas.DrawLine(0, 300, 500, 300); //----------------------------------------------------- canvas.StrokeColor = PixelFarm.Drawing.Color.Magenta; //draw line test canvas.DrawLine(20, 20, 600, 200); //----------------------------------------------------- //smooth with agg canvas.SmoothMode = CanvasSmoothMode.AggSmooth; var fillColor = new PixelFarm.Drawing.Color(50, 255, 0, 0); // PixelFarm.Drawing.Color.Red; //rect polygon var polygonCoords = new float[] { 5, 300, 40, 300, 50, 340, 10f, 340 }; //canvas.DrawPolygon(polygonCoords); //fill polygon test canvas.FillPolygon(fillColor, polygonCoords); var polygonCoords2 = new float[] { 5 + 10, 300, 40 + 10, 300, 50 + 10, 340, 10f + 10, 340 }; canvas.StrokeColor = new PixelFarm.Drawing.Color(100, 0, 255, 0); // L canvas.DrawPolygon(polygonCoords2, polygonCoords2.Length / 2); int strokeW = 10; canvas.StrokeColor = PixelFarm.Drawing.Color.LightGray; for (int i = 1; i < 90; i += 10) { canvas.StrokeWidth = strokeW; double angle = OpenTK.MathHelper.DegreesToRadians(i); canvas.DrawLine(20, 400, (float)(600 * Math.Cos(angle)), (float)(600 * Math.Sin(angle))); strokeW--; if (strokeW < 1) { strokeW = 1; } } var color = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Green); canvas.StrokeColor = color; ////--------------------------------------------- ////draw ellipse and circle canvas.StrokeWidth = 0.75f; canvas.DrawCircle(400, 500, 50); canvas.FillCircle(color, 450, 550, 25); canvas.StrokeWidth = 3; canvas.DrawRoundRect(500, 450, 100, 100, 10, 10); canvas.StrokeWidth = 3; canvas.StrokeColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Blue); //canvas.DrawBezierCurve(0, 0, 500, 500, 0, 250, 500, 250); canvas.DrawBezierCurve(120, 500 - 160, 220, 500 - 40, 35, 500 - 200, 220, 500 - 260); canvas.SmoothMode = CanvasSmoothMode.No; //canvas.DrawArc(150, 200, 300, 50, 0, 150, 150, SvgArcSize.Large, SvgArcSweep.Negative); canvas.DrawArc(100, 200, 300, 200, 30, 30, 50, SvgArcSize.Large, SvgArcSweep.Negative); // canvas.DrawArc(100, 200, 300, 200, 0, 100, 100, SvgArcSize.Large, SvgArcSweep.Negative); fillColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Black); canvas.StrokeColor = fillColor; canvas.DrawLine(100, 200, 300, 200); //load font data var font = PixelFarm.Agg.Fonts.NativeFontStore.LoadFont("c:\\Windows\\Fonts\\Tahoma.ttf", 64); var fontGlyph = font.GetGlyph('{'); //PixelFarm.Font2.MyFonts.SetShapingEngine(); canvas.FillVxs(fillColor, fontGlyph.flattenVxs); glTextPrinter.CurrentFont = font; canvas.StrokeColor = PixelFarm.Drawing.Color.Black; canvas.DrawLine(0, 200, 500, 200); //test Thai words glTextPrinter.Print("ดุดีดำด่าด่ำญญู", 80, 200); //number glTextPrinter.Print("1234567890", 80, 200); GLBitmap bmp = PixelFarm.Drawing.DrawingGL.GLBitmapTextureHelper.CreateBitmapTexture(fontGlyph.glyphImage32); canvas.DrawImage(bmp, 50, 50); bmp.Dispose(); }); form.Show(); }