/// <summary> /// bitblt /// </summary> /// <param name="buff"></param> /// <param name="img"></param> /// <param name="srcRect"></param> /// <param name="destRect"></param> public void DrawImage(FrameBuff buff, FrameBuff img, Rect srcRect, Rect destRect) { Texture2D tex = buff == null ? m_texture : (buff as frameBuff).texture; tex.SetPixels((int)destRect.x, (int)destRect.y, (int)destRect.width, (int)destRect.height, (img as frameBuff).texture.GetPixels((int)srcRect.x, (int)srcRect.y, (int)srcRect.width, (int)srcRect.height)); }
/// <summary> /// 画像素 /// </summary> /// <param name="buff"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="color"></param> public void SetPixel(FrameBuff buff, int x, int y, Color color) { if (buff == null) { m_texture.SetPixel(x, y, color); } else { (buff as frameBuff).texture.SetPixel(x, y, color); } }
// Use this for initialization void Start() { m_graph = RetroGraphCreator.InitGraph(120, 90, eGraphType.Texture); m_image = m_graph.CreateFrameBuff(10, 10); m_graph.Clear(null, Color.red); m_graph.Clear(m_image, Color.blue); m_graph.DrawLine(m_image, new Vector2(0, 4), new Vector2(9, 4), Color.green); }
/// <summary> /// 清除 /// </summary> /// <param name="buff"></param> /// <param name="color"></param> public void Clear(FrameBuff buff, Color color) { Texture2D tex = buff == null ? m_texture : (buff as frameBuff).texture; Color[] fillColor = new Color[tex.height * tex.width]; fillColor.Initialize(); for (int i = 0; i < fillColor.Length; i++) { fillColor[i] = color; } tex.SetPixels(fillColor); }
/// <summary> /// 画线 /// </summary> /// <param name="buff"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="color"></param> public void DrawLine(FrameBuff buff, Vector2 start, Vector2 end, Color color) { Texture2D tex = buff == null ? m_texture : (buff as frameBuff).texture; if (start.x == end.x) { for (int i = (int)start.y; i != (int)end.y; i += System.Math.Sign(end.y - start.y)) { tex.SetPixel((int)start.x, i, color); } } else { for (int i = (int)start.x; i != (int)end.x; i += System.Math.Sign(end.x - start.x)) { tex.SetPixel(i, (int)start.y, color); } } }