How do I draw lines using XNA?

后端 未结 10 1256
情书的邮戳
情书的邮戳 2020-12-05 04:19

I\'ve read a bunch of tutorials involving XNA (and it\'s various versions) and I still am a little confused on drawing primitives. Everything seems to be really convoluted.

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 04:51

    found a tutorial for that http://www.bit-101.com/blog/?p=2832

    its using a BasicEffect (shader) and the built in draw user primitive in XNA 4.0

    some code samples i find helpful:

    load content method

    basicEffect = new BasicEffect(GraphicsDevice);
    basicEffect.VertexColorEnabled = true;
    basicEffect.Projection = Matrix.CreateOrthographicOffCenter
    (0, GraphicsDevice.Viewport.Width,     // left, right
    GraphicsDevice.Viewport.Height, 0,    // bottom, top
    0, 1);   
    

    draw method

    basicEffect.CurrentTechnique.Passes[0].Apply();
    var vertices = new VertexPositionColor[4];
    vertices[0].Position = new Vector3(100, 100, 0);
    vertices[0].Color = Color.Black;
    vertices[1].Position = new Vector3(200, 100, 0);
    vertices[1].Color = Color.Red;
    vertices[2].Position = new Vector3(200, 200, 0);
    vertices[2].Color = Color.Black;
    vertices[3].Position = new Vector3(100, 200, 0);
    vertices[3].Color = Color.Red;
    
    GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 2);
    

    have fun and vote up if this helped you. also pay a visit to the tutorial i got this from.

提交回复
热议问题