Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In XNA, I have created a new VertexType, called it VertexPositionTextureLight which inherts the IVertexType Interface, but apparently I need to implement the member of VertexDeclartion which I cleary have:

struct VertexPositionTextureLight : IVertexType  {
    Vector3 position;
    Vector2 textureCoordinates;
    float light;

    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) * 5, VertexElementFormat.Single, VertexElementUsage.TextureCoordinate, 1));

    public VertexPositionTextureLight(Vector3 position, Vector3 normal, Vector2 textureCoordinate, float light)  {
        // TODO: Use normal data
        this.position = position;
        this.textureCoordinates = textureCoordinate;
        this.light = light;
    }
}

I used to use this struct without inheriting the interface but since I need to call the device.DrawUserIndexedPrimitives that function wants the struct to inherit IVertexType.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You should have this line also:

   VertexDeclaration IVertexType.VertexDeclaration
   {
       get { return VertexPositionTextureLight.VertexDeclaration; }
   }

It should work fine after that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.