I am trying to adjust the following code to render a quad on a 2D texture at a specific location and specific size. Currently this code will render a fullscreen quad, which makes sense since the POSITION
semantic is being set to the fullscreen size.
My issue, is that I don't know how to adjust the POSITION
semantics in the declaration below to use the specified location and size of a texture.
private short[] indexData = new short[] { 0, 1, 2, 2, 3, 0 };
private VertexPositionTexture[] CreateTriangles(Vector2 location,
float width, float height)
{
// how do I get these values, and where do I set them below?
float topleft = ??;
float topRight = ??;
float bottomLeft = ??;
float bottomRight = ??;
VertexPositionTexture[] vertices = new VertexPositionTexture[]
{
new VertexPositionTexture(new Vector3(1f, -1f, 0f),
new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(-1f, -1f, 0),
new Vector2(0, 1)),
new VertexPositionTexture(new Vector3(-1f, 1f, 0),
new Vector2(0, 0)),
new VertexPositionTexture(new Vector3(1f, 1f, 0),
new Vector2(1, 0))
};
return vertices;
}
All I'm trying to do is render a quad overtop of a texture at a specific location. If I use the code as-is with my texture is will stretch the texture to the entire size of the screen (again, makes sense because of how the POSITION
semantic is being set).