Skip to main content
Fix syntax error, fix indentation, improve irrelevant statement
Source Link

The VertexPositionTexture requires a .TextureCoordinate aswell.
(where 0f being the start, 1f being the end.)

The solution is just:

// VertexPositionTexture 
// (    Vector2 position (on screen UVViewport coordscoordinate [-1.0~10->1.0]),
//     Vector2 texturePosition (on texture UVTexture coordscoordinate [0.0~10->1.0]) 
VertexPositionTexture[] vertices = new VertexPositionTexture[4];VertexPositionTexture[4]
{
    new VertexPositionTexture(pointA, new Vector2(0f, 1f)),
    new VertexPositionTexture(pointB, new Vector2(0f, 0f)),
    new VertexPositionTexture(pointC, new Vector2(1f, 1f)),
    new VertexPositionTexture(pointD, new Vector2(1f, 0f)),
};

and replace the DrawUserIndexedPrimitives with

GraphicsDevice.DrawUserIndexedPrimitives(
    PrimitiveType.TriangleList, // drawing 2Specify trianglestri-based forquad aassembly
 square so using trianglelist
vertices,                   // theYour input verticiesvertices
    0,                          // verticesOffset offsetin vertex array (0 for noneno offset)
    4,                          // vertexLength countof (4the forinput fourvertices points)array
    new[] { 0, 1, 2, 1, 2, 3 }, // the indicesIndicies (a tri with index (0, 1, 2), and (1, 2, 3))
    0,                          // indiciesOffset offsetin index array (0 for none)
    2                           // numberNumber of tris to draw (2 for a square)
);

(turns out Note that MonoGame's DrawUserIndexedPrimitives's indices arethe input vertex array is order-sensitive. weird and you might get wrongly assembled quads if the order isn't correct.)

The VertexPositionTexture requires a .TextureCoordinate aswell.
(where 0f being the start, 1f being the end.)

The solution is just:

// VertexPositionTexture 
// ( Vector2 position (on screen UV coords [-1.0~1.0]),
//   Vector2 texturePosition (on texture UV coords [0.0~1.0]) 
VertexPositionTexture[] vertices = new VertexPositionTexture[4];
{
new VertexPositionTexture(pointA, new Vector2(0f, 1f)),
new VertexPositionTexture(pointB, new Vector2(0f, 0f)),
new VertexPositionTexture(pointC, new Vector2(1f, 1f)),
new VertexPositionTexture(pointD, new Vector2(1f, 0f)),
}

and replace the DrawUserIndexedPrimitives with

GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList, // drawing 2 triangles for a square so using trianglelist
vertices,                   // the input verticies
0,                          // vertices offset (0 for none)
4,                          // vertex count (4 for four points)
new[] { 0, 1, 2, 1, 2, 3 }, // the indices (a tri with index (0, 1, 2), and (1, 2, 3))
0,                          // indicies offset (0 for none)
2                           // number of tris to draw (2 for a square)
);

(turns out that MonoGame's DrawUserIndexedPrimitives's indices are order-sensitive. weird.)

The VertexPositionTexture requires a .TextureCoordinate aswell.
(where 0f being the start, 1f being the end.)

The solution is just:

// VertexPositionTexture 
//     Vector2 position (Viewport coordinate [-1.0->1.0]),
//     Vector2 texturePosition (Texture coordinate [0.0->1.0]
VertexPositionTexture[] vertices = new VertexPositionTexture[4]
{
    new VertexPositionTexture(pointA, new Vector2(0f, 1f)),
    new VertexPositionTexture(pointB, new Vector2(0f, 0f)),
    new VertexPositionTexture(pointC, new Vector2(1f, 1f)),
    new VertexPositionTexture(pointD, new Vector2(1f, 0f)),
};

and replace the DrawUserIndexedPrimitives with

GraphicsDevice.DrawUserIndexedPrimitives(
    PrimitiveType.TriangleList, // Specify tri-based quad assembly
    vertices,                   // Your input vertices
    0,                          // Offset in vertex array (0 for no offset)
    4,                          // Length of the input vertices array
    new[] { 0, 1, 2, 1, 2, 3 }, // Indicies (a tri with index (0, 1, 2), and (1, 2, 3))
    0,                          // Offset in index array (0 for none)
    2                           // Number of tris to draw (2 for a square)
);

Note that the input vertex array is order-sensitive and you might get wrongly assembled quads if the order isn't correct.

Source Link

The VertexPositionTexture requires a .TextureCoordinate aswell.
(where 0f being the start, 1f being the end.)

The solution is just:

// VertexPositionTexture 
// ( Vector2 position (on screen UV coords [-1.0~1.0]),
//   Vector2 texturePosition (on texture UV coords [0.0~1.0]) 
VertexPositionTexture[] vertices = new VertexPositionTexture[4];
{
new VertexPositionTexture(pointA, new Vector2(0f, 1f)),
new VertexPositionTexture(pointB, new Vector2(0f, 0f)),
new VertexPositionTexture(pointC, new Vector2(1f, 1f)),
new VertexPositionTexture(pointD, new Vector2(1f, 0f)),
}

and replace the DrawUserIndexedPrimitives with

GraphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.TriangleList, // drawing 2 triangles for a square so using trianglelist
vertices,                   // the input verticies
0,                          // vertices offset (0 for none)
4,                          // vertex count (4 for four points)
new[] { 0, 1, 2, 1, 2, 3 }, // the indices (a tri with index (0, 1, 2), and (1, 2, 3))
0,                          // indicies offset (0 for none)
2                           // number of tris to draw (2 for a square)
);

(turns out that MonoGame's DrawUserIndexedPrimitives's indices are order-sensitive. weird.)