public static CCTextureAtlas CreateAtlasFromTexture2D(Microsoft.Xna.Framework.Graphics.Texture2D texture2d) { CCTexture2D texture = new CCTexture2D(); texture.InitWithTexture(texture2d); CCTextureAtlas textureAtlas = CCTextureAtlas.Create(texture, 128); return textureAtlas; }
private void MakeTexture() { m_pTexture = new CCTexture2D(); m_pTexture.OnReInit = TextureReInit; m_pTexture.IsAntialiased = false; m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(m_Width, m_Height, m_ColorFormat, m_DepthFormat, m_Usage); m_pTexture.InitWithTexture(m_pRenderTarget2D, m_ColorFormat, true, false); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend; AddChild(m_pSprite); }
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage) { w = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor()); h = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor()); m_pTexture = new CCTexture2D(); m_pTexture.IsAntialiased = false; m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage); m_pTexture.InitWithTexture(m_pRenderTarget2D, colorFormat, true, false); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend; AddChild(m_pSprite); return(true); }
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage) { w = (int)Math.Ceiling(w * CCMacros.CCContentScaleFactor()); h = (int)Math.Ceiling(h * CCMacros.CCContentScaleFactor()); m_pTexture = new CCTexture2D(); m_pTexture.IsAntialiased = false; m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage); m_pTexture.InitWithTexture(m_pRenderTarget2D, colorFormat, true, false); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = CCBlendFunc.AlphaBlend; AddChild(m_pSprite); return true; }
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage) { w = (w * CCMacros.CCContentScaleFactor()); h = (h * CCMacros.CCContentScaleFactor()); m_pTexture = new CCTexture2D(); m_pTexture.SetAliasTexParameters(); m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage); m_pTexture.InitWithTexture(m_pRenderTarget2D); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); AddChild(m_pSprite); return true; }
protected virtual bool InitWithWidthAndHeight(int w, int h, SurfaceFormat colorFormat, DepthFormat depthFormat, RenderTargetUsage usage) { w = (w * CCMacros.CCContentScaleFactor()); h = (h * CCMacros.CCContentScaleFactor()); m_pTexture = new CCTexture2D(); m_pTexture.SetAliasTexParameters(); m_pRenderTarget2D = CCDrawManager.CreateRenderTarget(w, h, colorFormat, depthFormat, usage); m_pTexture.InitWithTexture(m_pRenderTarget2D); m_bFirstUsage = true; m_pSprite = new CCSprite(m_pTexture); //m_pSprite.scaleY = -1; m_pSprite.BlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); AddChild(m_pSprite); return(true); }
public CCTexture2D EndTexture() { Texture2D xnaTexture = new Texture2D(CCApplication.SharedApplication.GraphicsDevice, this.imageBuffer.Width, this.imageBuffer.Height); xnaTexture.SetData<byte>(this.imageBuffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return ccTexture; }
public static CCSprite CreateText(string text, CCColor4B fill, CCColor4B stroke, TypeFace font, double emSizeInPoints, bool underline = false, bool flatenCurves = true, double strokeThickness = 1) { TypeFacePrinter printer = new TypeFacePrinter(text, new StyledTypeFace(font, emSizeInPoints, underline, flatenCurves)); double width = printer.LocalBounds.Width; double height = printer.LocalBounds.Height; RectangleDouble rect = new RectangleDouble(); bounding_rect.bounding_rect_single(printer, 0, ref rect); VertexSourceApplyTransform path = new VertexSourceApplyTransform(printer, Affine.NewTranslation(-rect.Left, -rect.Bottom)); ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }
//矩形 public static CCSprite CreateRectangle( double width, double height, double radiusX, double radiusY, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1 ) { ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); RoundedRect path; if (stroke.A > 0) //有border { //border是以线的中间对齐,所以转换成int,如果是1个像素,正好变成零 int halfThickness = (int)(strokeThickness / 2); path = new RoundedRect(halfThickness, halfThickness, width - halfThickness, height - halfThickness, Math.Min(radiusX, radiusY)); } else { path = new RoundedRect(0, 0, width, height, Math.Min(radiusX, radiusY)); } if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }
//路径 public static CCSprite CreatePath( double width, double height, string[] paths, double contentX, double contentY, double contentWidth, double contentHeight, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1, UIGraphic.Stretch stretch = UIGraphic.Stretch.StretchNone ) { if (width == 0) width = contentWidth; if (height == 0) height = contentHeight; ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); double scalex = 0; double scaley = 0; //if (stretch == Stretch.StretchNone) { } else if (stretch == UIGraphic.Stretch.StretchFill) { if (width != contentWidth || height != contentHeight) { scalex = width / contentWidth; scaley = height / contentHeight; } } else if (stretch == UIGraphic.Stretch.StretchUniformToFill) { scalex = scaley = Math.Min(width / contentWidth, height / contentHeight); } foreach (string path in paths) { IVertexSource vertexs = MiniLanguage.CreatePathStorage(path); if (contentX != 0 || contentY != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewTranslation(-contentX, -contentY)); if (scalex != 0 || scaley != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewScaling(scalex, scaley)); if (fill.A > 0) g.Render(vertexs, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(vertexs, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); } Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }
public static CCSprite CreateLine( int width, int height, CCColor4B stroke, double strokeThickness = 1 ) { ImageBuffer buffer = new ImageBuffer(width, height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); if (stroke.A > 0) { //g.Line没有厚度 PathStorage linesToDraw = new PathStorage(); linesToDraw.remove_all(); linesToDraw.MoveTo(0, 0); linesToDraw.LineTo(width, height); Stroke StrockedLineToDraw = new Stroke(linesToDraw, strokeThickness); g.Render(StrockedLineToDraw, new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); } Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }
//圆形 public static CCSprite CreateEllipse( double width, double height, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1 ) { ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); MatterHackers.Agg.VertexSource.Ellipse path; if (stroke.A > 0) //有border { //border是以线的中间对齐,所以转换成int,如果是1个像素,正好变成零 int halfThickness = (int)(strokeThickness / 2); path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2 - halfThickness, height / 2 - halfThickness); } else { path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2, height / 2); } if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); Texture2D xnaTexture = XnaTexture((int)width, (int)height); xnaTexture.SetData<byte>(buffer.GetBuffer()); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return new CCSprite(ccTexture); }
public static CCTexture2D CCTextureFromPng(Stream pngStream) { Texture2D xnaTexture = XnaTextureFromPng(pngStream); CCTexture2D ccTexture = new CCTexture2D(); ccTexture.InitWithTexture(xnaTexture); return ccTexture; }
public void saveImage(object pSender) { using (var stream = new MemoryStream()) { m_pTarget.SaveToStream(stream, CCImageFormat.PNG); //m_pTarget.saveToFile(jpg, ImageFormat.JPG); stream.Position = 0; Texture2D xnatex = Texture2D.FromStream(CCDrawManager.GraphicsDevice, stream); var tex = new CCTexture2D(); tex.InitWithTexture(xnatex); CCSprite sprite = new CCSprite(tex); sprite.Scale = 0.3f; AddChild(sprite); sprite.Position = new CCPoint(40, 40); sprite.Rotation = counter * 3; } counter++; }