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 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); }