Monogame上的DrawUserPrimitives问题

时间:2013-08-13 00:07:24

标签: 3d xna xna-4.0 primitive monogame

我正在尝试使用3D基元DrawUserPrimitivesVertexPositionColor在Monogame(适用于Windows8)上绘制一个简单的彩色矩形,但我唯一能看到的是一个覆盖上半部分的矩形屏幕截图,如下面的屏幕截图所示。在绘制三角形时也会发生这种情况。

screenshot

这是我的代码:

// camera code
Camera.Position = new Vector3(0, 1500, 0);
Camera.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), GraphicsDevice.Viewport.AspectRatio, 1, 5000);
Camera.View = Matrix.CreateLookAt(Camera.Position, Vector3.Down, Vector3.Forward); 

VertexPositionColor[] vertexList = new VertexPositionColor[4]; 
BasicEffect basicEffect;  
VertexBuffer vertexBuffer;

// initializations
vertexList[0] = new VertexPositionColor(new Vector3(-957, 10, -635), Color.Red);  
vertexList[1] = new VertexPositionColor(new Vector3(957, 10, -635), Color.Lime);  
vertexList[2] = new VertexPositionColor(new Vector3(-957, 10, 635), Color.Yellow);  
vertexList[3] = new VertexPositionColor(new Vector3(957, 10, 635), Color.Blue);

vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 4, BufferUsage.WriteOnly);  
vertexBuffer.SetData<VertexPositionColor>(vertexList);

basicEffect = new BasicEffect(GraphicsDevice);  
basicEffect.VertexColorEnabled = true;  
basicEffect.LightingEnabled = false;  
basicEffect.Projection = Camera.Projection;

// draw code
GraphicsDevice.RasterizerState = RasterizerState.CullNone;
GraphicsDevice.SetVertexBuffer(vertexBuffer);

foreach (EffectPass p in basicEffect.CurrentTechnique.Passes)
{
   p.Apply();
   GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, vertexList, 0, 2);
}

正如你所看到的,我为所有四个顶点使用了不同的颜色,但程序实际上似乎只绘制了两个顶点:vertexList[0]vertexList[1]。 有什么建议吗?怎么了?

1 个答案:

答案 0 :(得分:3)

我认为你错过了

basicEffect.View = Camera.View;