public GridRenderer(Grid <T> _grid, Func <T, Color4> _colorSelector, float _tileWidth, float _tileHeight) { grid = _grid; tileWidth = _tileWidth; tileHeight = _tileHeight; var rectanglesVertices = new List <IEnumerable <ColoredVertex> >(); for (var i = 0; i < _grid.Width; i++) { for (var j = 0; j < _grid.Height; j++) { var rectangle = new Rectangle(i * tileWidth, j * tileHeight, tileWidth, tileHeight); var vertices = rectangle.ToVertices(); var tile = _grid.Get(i, j); var color = _colorSelector(tile); var coloredVertices = vertices.Select(v => new ColoredVertex(new Vector3(v.X, v.Y, 0), color)); rectanglesVertices.Add(coloredVertices); } } buffer = new ColoredVertexBuffer(PrimitiveType.Quads); buffer.AddVertices(rectanglesVertices.SelectMany(x => x)); Initialize(buffer); }
public ColoredVertexBuffer GetOutlineBuffer(Color4 _color) { var buffer = new ColoredVertexBuffer(PrimitiveType.LineLoop); ForEach(v => buffer.AddVertex(new ColoredVertex(v, _color))); return(buffer); }
public override ColoredVertexBuffer GetFillBuffer(Color4 _color) { var buffer = new ColoredVertexBuffer(PrimitiveType.Triangles); ToTriangles().ForEach(v => buffer.AddVertex(new ColoredVertex(v, _color))); return(buffer); }
public Cell(int _i, int _j, CellGrid _grid) { i = _i; j = _j; grid = _grid; value = 0; rectangleBuffer = ConvexPolygon.Square(_grid.CellSize).GetFillBuffer();//new ColoredRectangleBuffer(X, Y, _grid.CellSize, _grid.CellSize, -1.5f); }
public override ColoredVertexBuffer GetFillBuffer(Color4 _color) { //PrimitiveType.Polygon appears to only work for convex polygons var buffer = new ColoredVertexBuffer(PrimitiveType.Polygon); buffer.AddVertices(this.Select(x => new ColoredVertex(x, _color))); return(buffer); }
public static void Line(float x1, float y1, float x2, float y2, Color4?_color = null) { //Create var color = _color ?? Color4.White; var buffer = new ColoredVertexBuffer(PrimitiveType.Lines); buffer.AddVertex(new ColoredVertex(new Vector3(x1, y1, 0), color)); buffer.AddVertex(new ColoredVertex(new Vector3(x2, y2, 0), color)); var array = ColoredVertexArray.FromBuffer(buffer); //Use array.Render(); //Destroy buffer.Destroy(); array.Destroy(); }