DrawingGL.GLBitmap ResolveForGLBitmap(Image image) { var cacheBmp = Image.GetCacheInnerImage(image) as DrawingGL.GLBitmap; if (cacheBmp != null) { return(cacheBmp); } else { GLBitmap glBmp = null; if (image is ActualImage) { ActualImage actualImage = (ActualImage)image; glBmp = new GLBitmap(actualImage); } else { //TODO: review here //we should create 'borrow' method ? => send direct exact ptr to img buffer //for now, create a new one -- after we copy we, don't use it var req = new Image.ImgBufferRequestArgs(32, Image.RequestType.Copy); image.RequestInternalBuffer(ref req); int[] copy = req.OutputBuffer32; glBmp = new GLBitmap(image.Width, image.Height, copy, req.IsInvertedImage); } Image.SetCacheInnerImage(image, glBmp); return(glBmp); } }
public void DrawImageWithConv3x3(GLBitmap bmp, float[] kernel3x3, float x, float y) { conv3x3TextureShader.IsBigEndian = bmp.IsBigEndianPixel; conv3x3TextureShader.SetBitmapSize(bmp.Width, bmp.Height); conv3x3TextureShader.SetConvolutionKernel(kernel3x3); conv3x3TextureShader.Render(bmp, x, y, bmp.Width, bmp.Height); }
int GetTextureId(GLBitmap bmp) { //only after gl context is created int foundTextureId; if (!registerTextures.TryGetValue(bmp, out foundTextureId)) { //server part //gen texture GL.GenTextures(1, out foundTextureId); //add registerTextures.Add(bmp, foundTextureId); //bind GL.BindTexture(TextureTarget.Texture2D, foundTextureId); bmp.TransientLoadBufferHead((IntPtr bmpScan0) => { GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp.Width, bmp.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)bmpScan0); }); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); } else { } return(foundTextureId); }
public override void DrawImage(ActualImage actualImage, double x, double y) { GLBitmap glBmp = new GLBitmap(actualImage.Width, actualImage.Height, ActualImage.GetBuffer(actualImage), false); _canvas.DrawImage(glBmp, (float)x, (float)y); glBmp.Dispose(); }
public void DrawImageWithSubPixelRenderingMsdf(GLBitmap bmp, float x, float y, float scale) { msdfSubPixelRenderingShader.ForegroundColor = PixelFarm.Drawing.Color.Black; //msdfSubPixelRenderingShader.BackgroundColor = PixelFarm.Drawing.Color.Blue;//blue is suite for transparent bg msdfSubPixelRenderingShader.BackgroundColor = PixelFarm.Drawing.Color.White;//opaque white msdfSubPixelRenderingShader.Render(bmp, x, y, bmp.Width * scale, bmp.Height * scale); }
public GLBitmap GetGLBitmap() { return((_glBmp != null) ? _glBmp : _glBmp = new GLBitmap(_textureId, _width, _height) { IsBigEndianPixel = true, IsYFlipped = true }); }
//----------- void EnsureLoadGLBmp() { if (_glBmp == null) { _glBmp = _loadedGlyphs.GetOrCreateNewOne(simpleFontAtlas); } }
public void DrawString(char[] text, int startAt, int len, double x, double y) { if (this.UseSubPixelRendering) { //1. clear prev drawing result _aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0)); //aggPainter.Clear(Drawing.Color.White); //aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0)); //2. print text span into Agg Canvas textPrinter.DrawString(text, startAt, len, 0, 0); //3.copy to gl bitmap byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(actualImage); //------------------------------------------------------ GLBitmap glBmp = new GLBitmap(bmpWidth, bmpHeight, buffer, true); glBmp.IsInvert = false; //TODO: review font height canvas.DrawGlyphImageWithSubPixelRenderingTechnique(glBmp, (float)x, (float)y + 40); glBmp.Dispose(); } else { //1. clear prev drawing result _aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0)); //2. print text span into Agg Canvas textPrinter.DrawString(text, startAt, len, 0, 0); //3.copy to gl bitmap byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(actualImage); //------------------------------------------------------ GLBitmap glBmp = new GLBitmap(bmpWidth, bmpHeight, buffer, true); glBmp.IsInvert = false; //TODO: review font height canvas.DrawGlyphImage(glBmp, (float)x, (float)y + 40); glBmp.Dispose(); } }
public void ChangeFont(RequestFont font) { //from request font //we resolve it to actual font this.font = font; this._glyphLayout.ScriptLang = font.GetOpenFontScriptLang(); SimpleFontAtlas foundFontAtlas; ActualFont fontImp = ActiveFontAtlasService.GetTextureFontAtlasOrCreateNew(_fontLoader, font, out foundFontAtlas); if (foundFontAtlas != this.simpleFontAtlas) { //change to another font atlas _glBmp = null; this.simpleFontAtlas = foundFontAtlas; } _typeface = (Typography.OpenFont.Typeface)fontImp.FontFace.GetInternalTypeface(); float srcTextureScale = _typeface.CalculateToPixelScaleFromPointSize(simpleFontAtlas.OriginalFontSizePts); //scale at request float targetTextureScale = _typeface.CalculateToPixelScaleFromPointSize(font.SizeInPoints); _finalTextureScale = targetTextureScale / srcTextureScale; }
public override void DrawImage(Image actualImage, double left, double top, ICoordTransformer coordTx) { //TODO: implement transformation matrix GLBitmap glBmp = _pcx.ResolveForGLBitmap(actualImage); if (glBmp != null) { if (this.OriginX != 0 || this.OriginY != 0) { //TODO: review here } // coordTx = aff = aff * Affine.NewTranslation(this.OriginX, this.OriginY); Affine aff = coordTx as Affine; if (aff != null) { _pcx.DrawImageToQuad(glBmp, aff); } else { } //_pcx.DrawImage(glBmp, (float)left, (float)top); } }
public void LoadTexture1(GLBitmap bmp) { textureSubPixRendering.LoadGLBitmap(bmp); textureSubPixRendering.IsBigEndian = bmp.IsBigEndianPixel; textureSubPixRendering.SetColor(this.FontFillColor); textureSubPixRendering.SetIntensity(1f); }
/// <summary> /// get from cache or create a new one /// </summary> /// <param name="reqFont"></param> /// <returns></returns> public SimpleFontAtlas GetFontAtlas(RequestFont reqFont, out GLBitmap glBmp) { int fontKey = reqFont.FontKey; SimpleFontAtlas fontAtlas; if (!_createdAtlases.TryGetValue(fontKey, out fontAtlas)) { Typeface resolvedTypeface = textServices.ResolveTypeface(reqFont); //if we don't have //the create it SimpleFontAtlasBuilder atlasBuilder = null; var textureGen = new GlyphTextureBitmapGenerator(); textureGen.CreateTextureFontFromScriptLangs( resolvedTypeface, reqFont.SizeInPoints, _textureKind, _currentScriptLangs, (glyphIndex, glyphImage, outputAtlasBuilder) => { if (outputAtlasBuilder != null) { //finish atlasBuilder = outputAtlasBuilder; } } ); GlyphImage totalGlyphsImg = atlasBuilder.BuildSingleImage(); //create atlas fontAtlas = atlasBuilder.CreateSimpleFontAtlas(); fontAtlas.TotalGlyph = totalGlyphsImg; #if DEBUG //save glyph image for debug //PixelFarm.Agg.ActualImage.SaveImgBufferToPngFile( // totalGlyphsImg.GetImageBuffer(), // totalGlyphsImg.Width * 4, // totalGlyphsImg.Width, totalGlyphsImg.Height, // "d:\\WImageTest\\total_" + reqFont.Name + "_" + reqFont.SizeInPoints + ".png"); #endif //cache the atlas _createdAtlases.Add(fontKey, fontAtlas); // //calculate some commonly used values fontAtlas.SetTextureScaleInfo( resolvedTypeface.CalculateScaleToPixelFromPointSize(fontAtlas.OriginalFontSizePts), resolvedTypeface.CalculateScaleToPixelFromPointSize(reqFont.SizeInPoints)); //TODO: review here, use scaled or unscaled values fontAtlas.SetCommonFontMetricValues( resolvedTypeface.Ascender, resolvedTypeface.Descender, resolvedTypeface.LineGap, resolvedTypeface.CalculateRecommendLineSpacing()); } glBmp = _loadedGlyphs.GetOrCreateNewOne(fontAtlas); return(fontAtlas); }
public void DrawString(char[] text, int startAt, int len, double x, double y) { if (this.UseSubPixelRendering) { //1. clear prev drawing result _aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0)); //aggPainter.Clear(Drawing.Color.White); //aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0)); //2. print text span into Agg Canvas _vxsTextPrinter.DrawString(text, startAt, len, 0, 0); //3.copy to gl bitmap //byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(_actualImage); //------------------------------------------------------ GLBitmap glBmp = new GLBitmap(_actualImage); glBmp.IsInvert = false; //TODO: review font height if (StartDrawOnLeftTop) { y -= _vxsTextPrinter.FontLineSpacingPx; } _glsx.DrawGlyphImageWithSubPixelRenderingTechnique(glBmp, (float)x, (float)y); glBmp.Dispose(); } else { //1. clear prev drawing result _aggPainter.Clear(Drawing.Color.White); _aggPainter.StrokeColor = Color.Black; //2. print text span into Agg Canvas _vxsTextPrinter.StartDrawOnLeftTop = false; float dyOffset = _vxsTextPrinter.FontDescedingPx; _vxsTextPrinter.DrawString(text, startAt, len, 0, -dyOffset); //------------------------------------------------------ //debug save image from agg's buffer #if DEBUG //actualImage.dbugSaveToPngFile("d:\\WImageTest\\aa1.png"); #endif //------------------------------------------------------ //3.copy to gl bitmap //byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(_actualImage); //------------------------------------------------------ //debug save image from agg's buffer //------------------------------------------------------ //GLBitmap glBmp = new GLBitmap(bmpWidth, bmpHeight, buffer, true); GLBitmap glBmp = new GLBitmap(_actualImage); glBmp.IsInvert = false; //TODO: review font height //if (StartDrawOnLeftTop) //{ y += _vxsTextPrinter.FontLineSpacingPx; //} _glsx.DrawGlyphImage(glBmp, (float)x, (float)y + dyOffset); glBmp.Dispose(); } }
public void DrawImageWithBlurX(GLBitmap bmp, float x, float y) { //TODO: review here //not complete blurShader.IsBigEndian = bmp.IsBigEndianPixel; blurShader.IsHorizontal = true; blurShader.Render(bmp, x, y, bmp.Width, bmp.Height); }
public override void DrawImage(ActualImage actualImage, params AffinePlan[] affinePlans) { //create gl bmp GLBitmap glBmp = new GLBitmap(actualImage.Width, actualImage.Height, ActualImage.GetBuffer(actualImage), false); _canvas.DrawImage(glBmp, 0, 0); glBmp.Dispose(); }
public void Dispose() { if (_lookupBmp != null) { _lookupBmp.Dispose(); _lookupBmp = null; } }
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 virtual void Dispose() { if (_isCacheBmpOwner && CacheGradientBitmap != null) { CacheGradientBitmap.Dispose(); CacheGradientBitmap = null; } }
public override void Dispose() { base.Dispose(); if (_lookupBmp != null) { _lookupBmp.Dispose(); _lookupBmp = null; } }
public Framebuffer(GLBitmap glBmp, bool isBmpOwner) { _glBmp = glBmp; _width = glBmp.Width; _height = glBmp.Height; _isBmpOwner = isBmpOwner; InitFrameBuffer(); }
void UploadGradientLookupTable(GLBitmap bmp) { //load before use with RenderSubImage //------------------------------------------------------------------------------------- // Bind the texture... TextureContainter container = _shareRes.LoadGLBitmap(bmp); s_texture.SetValue(container.TextureUnitNo); }
public void Dispose() { _loadedGlyphs.Clear(); if (_glBmp != null) { _glBmp.Dispose(); _glBmp = null; } }
void UploadGradientLookupTable(GLBitmap bmp) { //load before use with RenderSubImage //------------------------------------------------------------------------------------- // Bind the texture... GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId()); // Set the texture sampler to texture unit to 0 s_texture.SetValue(0); }
public override void DrawImage(Image actualImage, params AffinePlan[] affinePlans) { //create gl bmp GLBitmap glBmp = ResolveForGLBitmap(actualImage);// new GLBitmap(actualImage.Width, actualImage.Height, ActualImage.GetBuffer(actualImage), false); if (glBmp != null) { _glsx.DrawImage(glBmp, 0, 0); } }
//public override void DrawImage(Image actualImage, double left, double top, ICoordTransformer coordTx) //{ // //draw img with transform coord // // // MemBitmap memBmp = actualImage as MemBitmap; // if (memBmp == null) // { // //? TODO // return; // } // if (_renderQuality == RenderQuality.Fast) // { // //todo, review here again // //TempMemPtr tmp = ActualBitmap.GetBufferPtr(actualImg); // //BitmapBuffer srcBmp = new BitmapBuffer(actualImage.Width, actualImage.Height, tmp.Ptr, tmp.LengthInBytes); // //_bxt.BlitRender(srcBmp, false, 1, new BitmapBufferEx.MatrixTransform(affinePlans)); // //if (affinePlans != null && affinePlans.Length > 0) // //{ // // _bxt.BlitRender(srcBmp, false, 1, new BitmapBufferEx.MatrixTransform(affinePlans)); // //} // //else // //{ // // //_bxt.BlitRender(srcBmp, false, 1, null); // // _bxt.Blit(0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight, srcBmp, 0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight, // // ColorInt.FromArgb(255, 255, 255, 255), // // BitmapBufferExtensions.BlendMode.Alpha); // //} // return; // } // bool useSubPix = UseSubPixelLcdEffect; //save, restore later... // //before render an image we turn off vxs subpixel rendering // this.UseSubPixelLcdEffect = false; // if (coordTx is Affine) // { // Affine aff = (Affine)coordTx; // if (this.OriginX != 0 || this.OriginY != 0) // { // coordTx = aff = aff * Affine.NewTranslation(this.OriginX, this.OriginY); // } // } // //_aggsx.SetScanlineRasOrigin(OriginX, OriginY); // _aggsx.Render(memBmp, coordTx); // //_aggsx.SetScanlineRasOrigin(xx, yy); // //restore... // this.UseSubPixelLcdEffect = useSubPix; //} public override void DrawImage(Image actualImage) { GLBitmap glBmp = _pcx.ResolveForGLBitmap(actualImage); if (glBmp == null) { return; } _pcx.DrawImage(glBmp, 0, 0); }
public override void DrawImage(Image actualImage, double left, double top) { GLBitmap glBmp = _pcx.ResolveForGLBitmap(actualImage); if (glBmp == null) { return; } _pcx.DrawImage(glBmp, (float)left, (float)top); }
public void DrawSubImageWithMsdf(GLBitmap bmp, ref PixelFarm.Drawing.Rectangle r, float targetLeft, float targetTop, float scale) { if (bmp.IsBigEndianPixel) { msdfShader.RenderSubImage(bmp, r.Left, r.Top, r.Width, r.Height, targetLeft, targetTop, scale); } else { msdfShader.RenderSubImage(bmp, r.Left, r.Top, r.Width, r.Height, targetLeft, targetTop, scale); } }
public void DrawSubImageWithMsdf(GLBitmap bmp, float[] coords, float scale) { if (bmp.IsBigEndianPixel) { msdfShader.RenderSubImages(bmp, coords, scale); } else { msdfShader.RenderSubImages(bmp, coords, scale); } }
public void DrawSubImage(GLBitmap bmp, ref PixelFarm.Drawing.Rectangle r, float targetLeft, float targetTop, float scale) { if (bmp.IsBigEndianPixel) { glesTextureShader.RenderSubImage(bmp, r.Left, r.Top, r.Width, r.Height, targetLeft, targetTop); } else { gdiImgTextureShader.RenderSubImage(bmp, r.Left, r.Top, r.Width, r.Height, targetLeft, targetTop); } }
public void DrawSubImage(GLBitmap bmp, float srcLeft, float srcTop, float srcW, float srcH, float targetLeft, float targetTop) { if (bmp.IsBigEndianPixel) { glesTextureShader.RenderSubImage(bmp, srcLeft, srcTop, srcW, srcH, targetLeft, targetTop); } else { gdiImgTextureShader.RenderSubImage(bmp, srcLeft, srcTop, srcW, srcH, targetLeft, targetTop); } }
public void RenderSubImage(GLBitmap bmp, float srcLeft, float srcTop, float srcW, float srcH, float targetLeft, float targetTop, float scale) { //SetCurrent(); //CheckViewMatrix(); ////------------------------------------------------------------------------------------- //// Bind the texture... //GL.ActiveTexture(TextureUnit.Texture0); //GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId()); //// Set the texture sampler to texture unit to 0 //s_texture.SetValue(0); //OnSetVarsBeforeRenderer(); //float srcBottom = srcTop - srcH; //float srcRight = srcLeft + srcW; //float orgBmpW = bmp.Width; //float orgBmpH = bmp.Height; //unsafe //{ // float* imgVertices = stackalloc float[5 * 4]; // { // imgVertices[0] = targetLeft; imgVertices[1] = targetTop; imgVertices[2] = 0; //coord 0 // imgVertices[3] = srcLeft / orgBmpW; imgVertices[4] = srcBottom / orgBmpH; //texture coord 0 // //--------------------- // imgVertices[5] = targetLeft; imgVertices[6] = targetTop - (srcH * scale); imgVertices[7] = 0; //coord 1 // imgVertices[8] = srcLeft / orgBmpW; imgVertices[9] = srcTop / orgBmpH; //texture coord 1 // //--------------------- // imgVertices[10] = targetLeft + (srcW * scale); imgVertices[11] = targetTop; imgVertices[12] = 0; //coord 2 // imgVertices[13] = srcRight / orgBmpW; imgVertices[14] = srcBottom / orgBmpH; //texture coord 2 // //--------------------- // imgVertices[15] = targetLeft + (srcW * scale); imgVertices[16] = targetTop - (srcH * scale); imgVertices[17] = 0; //coord 3 // imgVertices[18] = srcRight / orgBmpW; imgVertices[19] = srcTop / orgBmpH; //texture coord 3 // }; // a_position.UnsafeLoadMixedV3f(imgVertices, 5); // a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5); //} //GL.DrawElements(BeginMode.TriangleStrip, 4, DrawElementsType.UnsignedShort, indices); RenderSubImage(bmp, new float[]{ srcLeft,srcTop, srcW,srcH, targetLeft, targetTop }, scale); }
public void Print(char[] buffer, double x, double y) { int j = buffer.Length; int buffsize = j * 2; //get kerning list ActualFont fontImp = nativeFontStore.GetResolvedNativeFont(currentFont); if (properGlyphs == null) { properGlyphs = new ProperGlyph[buffsize]; TextShapingService.GetGlyphPos(fontImp, buffer, 0, buffsize, properGlyphs); } double xpos = x; for (int i = 0; i < buffsize; ++i) { uint codepoint = properGlyphs[i].codepoint; if (codepoint == 0) { break; } //------------------------------------------------------------- FontGlyph glyph = fontImp.GetGlyphByIndex(codepoint); //glyph image32 //------------------------------------------------------------- GLBitmap bmp = new GLBitmap(new LazyAggBitmapBufferProvider(glyph.glyphImage32)); var left = glyph.glyphMatrix.img_horiBearingX; this.canvas2d.DrawImage(bmp, (float)(xpos + (left >> 6)), (float)(y + (glyph.glyphMatrix.bboxYmin >> 6))); int w = (glyph.glyphMatrix.advanceX) >> 6; xpos += (w); bmp.Dispose(); //temp here //------------------------------------------------------------- } }
public override void DrawString(string text, double x, double y) { char[] chars = text.ToCharArray(); int j = chars.Length; int buffsize = j * 2; //get kerning list //get actual font for this canvas TextureFont currentFont = _currentTextureFont; SimpleFontAtlas fontAtlas = currentFont.FontAtlas; ProperGlyph[] properGlyphs = new ProperGlyph[buffsize]; TextShapingService.GetGlyphPos(currentFont, chars, 0, buffsize, properGlyphs); GLBitmap glBmp = (GLBitmap)currentFont.GLBmp; if (glBmp == null) { //create glbmp GlyphImage glyphImage = fontAtlas.TotalGlyph; int[] buffer = glyphImage.GetImageBuffer(); glBmp = new GLBitmap(glyphImage.Width, glyphImage.Height, buffer, false); } //int j = chars.Length; // float c_x = (float)x; float c_y = (float)y; //TODO: review here *** //----------------- //1. layout each glyph before render *** // float baseline = c_y - 24;//eg line height= 24 //create a list //-------------- List<float> coords = new List<float>(); float scale = 1f; for (int i = 0; i < buffsize; ++i) { ProperGlyph glyph1 = properGlyphs[i]; uint codepoint = properGlyphs[i].codepoint; if (codepoint == 0) { break; } //-------------------------------- //if (codepoint == 1173 && i > 1) //{ // //check prev code point // codepoint = 1168; //} //-------------------------------- TextureFontGlyphData glyphData; if (!fontAtlas.GetRectByCodePoint((int)codepoint, out glyphData)) { //Rectangle r = glyphData.Rect; //float x_min = glyphData.BBoxXMin / 64; ////draw each glyph at specific position ////_canvas.DrawSubImageWithMsdf(glBmp, ref r, c_x + x_min, (float)(baseline + r.Height)); //_canvas.DrawSubImageWithMsdf(glBmp, ref r, c_x + x_min, (float)(baseline + r.Height)); ////c_x += r.Width - 10; //c_x += (glyphData.AdvanceX / 64); continue; } FontGlyph glyph = currentFont.GetGlyphByIndex(codepoint); int left = ((int)(glyph.glyphMatrix.img_horiBearingX * scale) >> 6); Rectangle r = glyphData.Rect; int adjustX = 0; int bboxYMin = glyph.glyphMatrix.bboxYmin >> 6; if (bboxYMin > 1 || bboxYMin < -1) { // adjustX = 3; } //scale down 0.8; //_canvas.DrawSubImageWithMsdf(glBmp, ref r, adjustX + c_x + left, // (float)(baseline + ((int)(glyphData.ImgHeight + glyph.glyphMatrix.bboxYmin) >> 6)), 1.1f); coords.Add(r.Left); coords.Add(r.Top); coords.Add(r.Width); coords.Add(r.Height); //------------------------- coords.Add(adjustX + c_x + left); //coords.Add(baseline + ((int)((glyphData.ImgHeight + glyph.glyphMatrix.bboxYmin) * scale) >> 6)); coords.Add(baseline + ((int)((glyphData.ImgHeight + glyphData.BBoxYMin) * scale) >> 6)); //int w = (int)(glyph.glyphMatrix.advanceX * scale) >> 6; int w = (int)(glyph.horiz_adv_x * scale) >> 6; c_x += w; } _canvas.DrawSubImageWithMsdf(glBmp, coords.ToArray(), scale); }
public void DrawImage(GLBitmap bmp, float x, float y, float w, float h) { DrawImage(bmp, new Drawing.RectangleF(0, 0, bmp.Width, bmp.Height), x, y, w, h); }
public void DrawSubImage(GLBitmap bmp, ref PixelFarm.Drawing.Rectangle r, float targetLeft, float targetTop) { if (bmp.IsBigEndianPixel) { glesTextureShader.RenderSubImage(bmp, r.Left, r.Top, r.Width, r.Height, targetLeft, targetTop); } else { gdiImgTextureShader.RenderSubImage(bmp, r.Left, r.Top, r.Width, r.Height, targetLeft, targetTop); } }
public void DrawSubImageWithMsdf(GLBitmap bmp, float[] coords, float scale) { if (bmp.IsBigEndianPixel) { msdfShader.RenderSubImage(bmp, coords, scale); } else { msdfShader.RenderSubImage(bmp, coords, scale); } }
public void DrawImageWithWhiteTransparent(GLBitmap bmp, float x, float y) { this.gdiImgTextureWithWhiteTransparentShader.Render(bmp, x, y, bmp.Width, bmp.Height); }
public void DrawImage(GLBitmap bmp, Drawing.RectangleF srcRect, float x, float y, float w, float h) { if (bmp.IsBigEndianPixel) { glesTextureShader.Render(bmp, x, y, w, h); } else { gdiImgTextureShader.Render(bmp, x, y, w, h); } }
public void Render(GLBitmap bmp, float left, float top, float w, float h) { unsafe { float* imgVertices = stackalloc float[5 * 4]; { imgVertices[0] = left; imgVertices[1] = top; imgVertices[2] = 0; //coord 0 imgVertices[3] = 0; imgVertices[4] = 0; //texture coord 0 //--------------------- imgVertices[5] = left; imgVertices[6] = top - h; imgVertices[7] = 0; //coord 1 imgVertices[8] = 0; imgVertices[9] = 1; //texture coord 1 //--------------------- imgVertices[10] = left + w; imgVertices[11] = top; imgVertices[12] = 0; //coord 2 imgVertices[13] = 1; imgVertices[14] = 0; //texture coord 2 //--------------------- imgVertices[15] = left + w; imgVertices[16] = top - h; imgVertices[17] = 0; //coord 3 imgVertices[18] = 1; imgVertices[19] = 1; //texture coord 3 }; a_position.UnsafeLoadMixedV3f(imgVertices, 5); a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5); } SetCurrent(); CheckViewMatrix(); //------------------------------------------------------------------------------------- // Bind the texture... GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId()); // Set the texture sampler to texture unit to 0 s_texture.SetValue(0); OnSetVarsBeforeRenderer(); GL.DrawElements(BeginMode.TriangleStrip, 4, DrawElementsType.UnsignedShort, indices); }
public void DrawString(CanvasGL2d canvas, string text, float x, float y) { char[] textBuffer = text.ToCharArray(); Win32.MyWin32.PatBlt(memdc.DC, 0, 0, bmpWidth, bmpHeight, Win32.MyWin32.WHITENESS); Win32.NativeTextWin32.TextOut(memdc.DC, 0, 0, textBuffer, textBuffer.Length); // Win32.Win32Utils.BitBlt(hdc, 0, 0, bmpWidth, 50, memHdc, 0, 0, Win32.MyWin32.SRCCOPY); //--------------- int stride = 4 * ((bmpWidth * 32 + 31) / 32); //Bitmap newBmp = new Bitmap(bmpWidth, 50, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var bmpData = newBmp.LockBits(new Rectangle(0, 0, bmpWidth, 50), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); byte[] tmp1 = new byte[stride * 50]; System.Runtime.InteropServices.Marshal.Copy(memdc.PPVBits, tmp1, 0, tmp1.Length); //--------------- int pos = 3; for (int r = 0; r < 50; ++r) { for (int c = 0; c < stride; ++c) { tmp1[pos] = 255; pos += 4; c += 4; } } Win32.NativeTextWin32.WIN32SIZE win32Size; unsafe { fixed (char* bufferHead = &textBuffer[0]) { Win32.NativeTextWin32.GetTextExtentPoint32Char(memdc.DC, bufferHead, textBuffer.Length, out win32Size); } } bmpWidth = win32Size.Width; bmpHeight = win32Size.Height; var actualImg = new Agg.ActualImage(bmpWidth, bmpHeight, Agg.PixelFormat.ARGB32); //------------------------------------------------------ //copy bmp from specific bmp area //and convert to GLBmp byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(actualImg); unsafe { byte* header = (byte*)memdc.PPVBits; fixed (byte* dest0 = &buffer[0]) { byte* dest = dest0; byte* rowHead = header; int rowLen = bmpWidth * 4; for (int h = 0; h < bmpHeight; ++h) { header = rowHead; for (int n = 0; n < rowLen; ) { //move next *(dest + 0) = *(header + 0); *(dest + 1) = *(header + 1); *(dest + 2) = *(header + 2); //*(dest + 3) = *(header + 3); *(dest + 3) = 255; header += 4; dest += 4; n += 4; } //finish one row rowHead += stride; } } } //------------------------------------------------------ GLBitmap glBmp = new GLBitmap(bmpWidth, bmpHeight, buffer, false); canvas.DrawImage(glBmp, (float)x, (float)y); glBmp.Dispose(); }
public void DrawImageWithSdf(GLBitmap bmp, float x, float y, float scale) { sdfShader.ForegroundColor = PixelFarm.Drawing.Color.Black; sdfShader.Render(bmp, x, y, bmp.Width * scale, bmp.Height * scale); }
public void RenderSubImage(GLBitmap bmp, float[] srcDestList, float scale) { SetCurrent(); CheckViewMatrix(); //------------------------------------------------------------------------------------- // Bind the texture... GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, bmp.GetServerTextureId()); // Set the texture sampler to texture unit to 0 s_texture.SetValue(0); OnSetVarsBeforeRenderer(); int j = srcDestList.Length; for (int i = 0; i < j; ) { float srcLeft = srcDestList[i]; float srcTop = srcDestList[i + 1]; float srcW = srcDestList[i + 2]; float srcH = srcDestList[i + 3]; float targetLeft = srcDestList[i + 4]; float targetTop = srcDestList[i + 5]; i += 6; //------------------------------- float srcBottom = srcTop - srcH; float srcRight = srcLeft + srcW; float orgBmpW = bmp.Width; float orgBmpH = bmp.Height; unsafe { float* imgVertices = stackalloc float[5 * 4]; { imgVertices[0] = targetLeft; imgVertices[1] = targetTop; imgVertices[2] = 0; //coord 0 imgVertices[3] = srcLeft / orgBmpW; imgVertices[4] = srcBottom / orgBmpH; //texture coord 0 //--------------------- imgVertices[5] = targetLeft; imgVertices[6] = targetTop - (srcH * scale); imgVertices[7] = 0; //coord 1 imgVertices[8] = srcLeft / orgBmpW; imgVertices[9] = srcTop / orgBmpH; //texture coord 1 //--------------------- imgVertices[10] = targetLeft + (srcW * scale); imgVertices[11] = targetTop; imgVertices[12] = 0; //coord 2 imgVertices[13] = srcRight / orgBmpW; imgVertices[14] = srcBottom / orgBmpH; //texture coord 2 //--------------------- imgVertices[15] = targetLeft + (srcW * scale); imgVertices[16] = targetTop - (srcH * scale); imgVertices[17] = 0; //coord 3 imgVertices[18] = srcRight / orgBmpW; imgVertices[19] = srcTop / orgBmpH; //texture coord 3 }; a_position.UnsafeLoadMixedV3f(imgVertices, 5); a_texCoord.UnsafeLoadMixedV2f(imgVertices + 3, 5); } GL.DrawElements(BeginMode.TriangleStrip, 4, DrawElementsType.UnsignedShort, indices); } }
public void DrawImageWithMsdf(GLBitmap bmp, float x, float y) { msdfShader.ForegroundColor = PixelFarm.Drawing.Color.Black; msdfShader.Render(bmp, x, y, bmp.Width, bmp.Height); }