I think you're missing
basicEffect.View = Camera.View;
Question
I'm trying to draw a simple coloured rectangle on Monogame (for Windows8) using the 3D primitives DrawUserPrimitives
and VertexPositionColor
, but the only thing I can see is a rectangle that covers the upper half of the screen, as you can see in the screenshot below. This occurs when drawing a triangle, too.
Here's my code:
// 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);
}
As you can see, I've used different colors for all four vertexes, but the program actually seems to draw only two of them: vertexList[0]
and vertexList[1]
.
Any suggestion? What's wrong?
Solution
I think you're missing
basicEffect.View = Camera.View;