protected override void Render(Gwen.Skin.Base skin) { if (dirty) { dirty = false; byte[] pixelData = new byte[Width * Height * 4]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { int XLoc = (int)((((float)x) / Width) * gltex.Width); int YLoc = (int)((((float)y) / Height) * gltex.Height); Color c = gltex.Image.GetPixel(XLoc, YLoc); pixelData[4 * (x + y * Width)] = c.R; pixelData[4 * (x + y * Width) + 1] = c.G; pixelData[4 * (x + y * Width) + 2] = c.B; pixelData[4 * (x + y * Width) + 3] = c.A; } } tex = new Gwen.Texture(skin.Renderer); tex.Width = Width; tex.Height = Height; tex.LoadRaw(Width, Height, pixelData); } skin.Renderer.DrawColor = Color.White; skin.Renderer.DrawTexturedRect(tex, RenderBounds); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="width">The width of the backing store in pixels.</param> /// <param name="height">The height of the backing store in pixels.</param> /// <param name="renderer">GWEN renderer.</param> public TextRenderer(int width, int height, FreezingArcherGwenRenderer renderer) { if (width <= 0) throw new ArgumentOutOfRangeException("width"); if (height <= 0) throw new ArgumentOutOfRangeException("height"); bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); gfx = Graphics.FromImage(bmp); gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; // NOTE: TextRenderingHint.AntiAliasGridFit looks sharper and in most cases better // but it comes with a some problems. // // 1. Graphic.MeasureString and format.MeasureCharacterRanges // seem to return wrong values because of this. // // 2. While typing the kerning changes in random places in the sentence. // // Until 1st problem is fixed we should use TextRenderingHint.AntiAlias... :-( gfx.TextRenderingHint = TextRenderingHint.AntiAlias; gfx.Clear(Color.Transparent); texture = new Texture(renderer) {Width = width, Height = height}; }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="width">The width of the backing store in pixels.</param> /// <param name="height">The height of the backing store in pixels.</param> /// <param name="renderer">GWEN renderer.</param> public TextRenderer(int width, int height, Renderer.OpenTK renderer) { if (width <= 0) throw new ArgumentOutOfRangeException("width"); if (height <= 0) throw new ArgumentOutOfRangeException("height"); if (GraphicsContext.CurrentContext == null) throw new InvalidOperationException("No GraphicsContext is current on the calling thread."); bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); gfx = Graphics.FromImage(bmp); // NOTE: TextRenderingHint.AntiAliasGridFit looks sharper and in most cases better // but it comes with a some problems. // // 1. Graphic.MeasureString and format.MeasureCharacterRanges // seem to return wrong values because of this. // // 2. While typing the kerning changes in random places in the sentence. // // Until 1st problem is fixed we should use TextRenderingHint.AntiAlias... :-( gfx.TextRenderingHint = TextRenderingHint.AntiAlias; gfx.Clear(Color.Transparent); texture = new Texture(renderer) {Width = width, Height = height}; }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="width">The width of the backing store in pixels.</param> /// <param name="height">The height of the backing store in pixels.</param> /// <param name="renderer">GWEN renderer.</param> public TextRenderer(int width, int height, Renderer.OpenTK renderer) { if (width <= 0) { throw new ArgumentOutOfRangeException("width"); } if (height <= 0) { throw new ArgumentOutOfRangeException("height"); } if (GraphicsContext.CurrentContext == null) { throw new InvalidOperationException("No GraphicsContext is current on the calling thread."); } bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); gfx = Graphics.FromImage(bmp); // NOTE: TextRenderingHint.AntiAliasGridFit looks sharper and in most cases better // but it comes with a some problems. // // 1. Graphic.MeasureString and format.MeasureCharacterRanges // seem to return wrong values because of this. // // 2. While typing the kerning changes in random places in the sentence. // // Until 1st problem is fixed we should use TextRenderingHint.AntiAlias... :-( gfx.TextRenderingHint = TextRenderingHint.AntiAlias; gfx.Clear(Color.Transparent); texture = new Texture(renderer) { Width = width, Height = height }; }
public override void DrawTexturedRect(Gwen.Texture tex, Rectangle targetRect, Color clr, float u1 = 0, float v1 = 0, float u2 = 1, float v2 = 1) { if (tex.RendererData != null) { UnityEngine.Texture uTex = (UnityEngine.Texture)tex.RendererData; DrawTexturedRect(uTex, targetRect, clr, u1, v1, u2, v2); } else { DrawMissingImage(targetRect); } }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="width">The width of the backing store in pixels.</param> /// <param name="height">The height of the backing store in pixels.</param> /// <param name="renderer">GWEN renderer.</param> public TextRenderer(int width, int height, Renderer.Tao renderer) { if (width <= 0) throw new ArgumentOutOfRangeException("width"); if (height <= 0) throw new ArgumentOutOfRangeException("height"); bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); gfx = Graphics.FromImage(bmp); //gfx.TextRenderingHint = TextRenderingHint.AntiAlias; gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; gfx.Clear(Color.Transparent); texture = new Texture(renderer) { Width = width, Height = height }; }
public static TextureRenderInfo BuildSingleTexture(Gwen.Renderer.Tao renderer, string url) { if (!ResProtocol.IsSingleTexture(url)) { return(null); } AssetDesc desc = Scene.Instance.GetAssetDesc(url); if (desc == null) { return(null); } string fullpath = Path.Combine(GState.AssetRoot, SysUtil.ToWindowsPath(desc.Path)); if (!File.Exists(fullpath)) { return(null); } Gwen.Texture t; t = new Gwen.Texture(renderer); if (t == null) { return(null); } t.Load(fullpath); if (t.Failed) { return(null); } TextureRenderInfo tri = new TextureRenderInfo(); tri.u1 = 0; tri.v1 = 0; tri.u2 = 1; tri.v2 = 1; tri.texture = t; return(tri); }
public Atlas GetAtlas(Gwen.Renderer.Tao renderer, string filePath) { // 先在缓存里找 Atlas ret; if (m_lut.TryGetValue(filePath, out ret)) { return(ret); } // 加载贴图,如果这个过程失败,那么认为 atlas 加载失败 Gwen.Texture t; t = new Gwen.Texture(renderer); if (t == null) { return(null); } t.Load(filePath + ResProtocol.ResImageFilePostfix); if (t.Failed) { return(null); } // 加载描述文件,如果这个过程失败,仍返回有效的 atlas string descFilePath = filePath + ResProtocol.ResDescFilePostfix; JObject desc = null; if (File.Exists(descFilePath)) { desc = ucore.JsonUtil.ReadTextIntoJObject(filePath + ResProtocol.ResDescFilePostfix); } // 拼装成有效的 atlas ret = new Atlas(); ret.FilePath = filePath; ret.Texture = t; ret.Desc = desc; return(ret); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="width">The width of the backing store in pixels.</param> /// <param name="height">The height of the backing store in pixels.</param> /// <param name="renderer">GWEN renderer.</param> public TextRenderer(int width, int height, Renderer.Tao renderer) { if (width <= 0) { throw new ArgumentOutOfRangeException("width"); } if (height <= 0) { throw new ArgumentOutOfRangeException("height"); } bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); gfx = Graphics.FromImage(bmp); //gfx.TextRenderingHint = TextRenderingHint.AntiAlias; gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; gfx.Clear(Color.Transparent); texture = new Texture(renderer) { Width = width, Height = height }; }