This is how I did it in Riemers Series 3D 3 HLSL overview
(Windows/Visual Studio 2019 Community/XNA 4.0)
namespace XNAseries3
{
public struct MyOwnVertexFormat
{
public Vector3 Position;
private Vector2 TexCoord;
private Vector3 Normal;
public MyOwnVertexFormat(Vector3 position, Vector2 texCoord, Vector3 normal)
{
this.Position = position;
this.TexCoord = texCoord;
this.Normal = normal;
}
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
new VertexElement(sizeof(float) * (3 + 2), VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)
);
}
//…
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.SetVertexBuffer(vertexBuffer);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, MyOwnVertexFormat.VertexDeclaration.VertexStride);
}
BTW
I would change this:
rs.FillMode = FillMode.WireFrame;
to:
rs.FillMode = FillMode.Solid;
// Here’s an example of IVertexType implementation
public struct VertexPositionNormalTangentBinormalTexture : IVertexType
{
public Vector3 Position;
public Vector3 Normal;
public Vector2 TextureCoordinate;
public Vector3 Tanget;
public Vector3 Binormal;
public static readonly VertexElement[] VertexElements = new VertexElement[]
{
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
new VertexElement(32, VertexElementFormat.Vector3, VertexElementUsage.Tangent, 0),
new VertexElement(44, VertexElementFormat.Vector3, VertexElementUsage.Binormal, 0)
};
public static readonly VertexDeclaration MyVertexDeclaration = new VertexDeclaration(VertexElements);
// (enables implementation of IVertexType)
public VertexDeclaration VertexDeclaration
{
get { return MyVertexDeclaration; }
}
public static readonly int SizeInBytes = sizeof(float) * (3 + 3 + 2 + 3 + 3);
}
// now the custom type can be used:
// typeof(VertexPositionNormalTangentBinormalTexture)