/// <summary> /// Render a (textured) quad to the screen. /// </summary> /// <param name="position">The position of the quad.</param> /// <param name="size">The size of the quad.</param> /// <param name="color">The color of the quad.</param> /// <param name="texture">The texture of the quad, if any.</param> /// <param name="textureArea">The texture area of the quad's texture, if any.</param> /// <param name="flipX">Whether to flip the texture on the x axis.</param> /// <param name="flipY">Whether to flip the texture on the y axis.</param> public void RenderSprite(Vector3 position, Vector2 size, Color color, Texture texture = null, Rectangle?textureArea = null, bool flipX = false, bool flipY = false) { SpriteBatchBase <VertexData> batch = GetBatch(); Span <VertexData> vertices = batch.GetData(texture); Debug.Assert(vertices.Length >= 4); VertexData.SpriteToVertexData(vertices, position, size, color, texture, textureArea, flipX, flipY); }
/// <summary> /// Render a line made out of quads. /// </summary> /// <param name="pointOne">The point to start the line.</param> /// <param name="pointTwo">The point to end the line at.</param> /// <param name="color">The color of the line.</param> /// <param name="thickness">The thickness of the line.</param> public void RenderLine(Vector3 pointOne, Vector3 pointTwo, Color color, float thickness = 1f) { SpriteBatchBase <VertexData> batch = GetBatch(); Span <VertexData> vertices = batch.GetData(null); Vector2 normal = Vector2.Normalize(new Vector2(pointTwo.Y - pointOne.Y, -(pointTwo.X - pointOne.X))) * thickness; float z = Math.Max(pointOne.Z, pointTwo.Z); vertices[0].Vertex = new Vector3(pointOne.X + normal.X, pointOne.Y + normal.Y, z); vertices[1].Vertex = new Vector3(pointTwo.X + normal.X, pointTwo.Y + normal.Y, z); vertices[2].Vertex = new Vector3(pointTwo.X - normal.X, pointTwo.Y - normal.Y, z); vertices[3].Vertex = new Vector3(pointOne.X - normal.X, pointOne.Y - normal.Y, z); uint c = color.ToUint(); vertices[0].Color = c; vertices[1].Color = c; vertices[2].Color = c; vertices[3].Color = c; }
/// <summary> /// Renders a sprite without a texture, but with uploaded UVs. /// If no uvRect is provided 0, 1, 1, 0 is uploaded instead. /// </summary> public void RenderUVRect(Vector3 pos, Vector2 size, Color color, Rectangle?uvRect = null) { SpriteBatchBase <VertexData> batch = GetBatch(); Span <VertexData> vertices = batch.GetData(null); vertices[0].Vertex = pos; vertices[1].Vertex = new Vector3(pos.X + size.X, pos.Y, pos.Z); vertices[2].Vertex = new Vector3(pos.X + size.X, pos.Y + size.Y, pos.Z); vertices[3].Vertex = new Vector3(pos.X, pos.Y + size.Y, pos.Z); uint c = color.ToUint(); vertices[0].Color = c; vertices[1].Color = c; vertices[2].Color = c; vertices[3].Color = c; Rectangle uv = uvRect ?? new Rectangle(0, 1, 1, 0); vertices[0].UV = new Vector2(uv.X, uv.Y); vertices[1].UV = new Vector2(uv.Width, uv.Y); vertices[2].UV = new Vector2(uv.Width, uv.Height); vertices[3].UV = new Vector2(uv.X, uv.Height); }