DrawUserIndexedPrimitives has 1px offset

Hey guys,

I have some stange issue with my xna port. In XNA I used a litte lib to draw lines into my editor. In Monogame this lines have a strange offset of one pixel. Here a some screenshots:

Monogame: https://www.dropbox.com/s/ixv9qviiwu85niy/monogamewrong.png?dl=0
XNA: https://www.dropbox.com/s/ixv9qviiwu85niy/monogamewrong.png?dl=0

Platform is windows 10 with DX and current monogame nuget build

The code is very short:
this.effect = new BasicEffect(this.GraphicsDevice); this.effect.VertexColorEnabled = true; this.effect.View = Matrix.Identity;// Matrix.CreateLookAt(new Vector3(0f, 0f, 1f), Vector3.Zero, Vector3.Up); this.effect.Projection = Matrix.CreateOrthographicOffCenter (0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);

protected override void Draw(GameTime gameTime)
    short[] indexData = { 0, 1 };
    VertexPositionColor[] vertexData =
    new VertexPositionColor(new Vector3(10, 10, 0), Color.Red),
    new VertexPositionColor(new Vector3(100, 10, 0), Color.Red)

    // TODO: Add your drawing code here
    this.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, vertexData, 0, 2, indexData, 0, 1);


I’m not sure but could this be related to the “half pixel offset”?

I think DX9 (so XNA) required a half pixel offset correction for some operations, but not anymore in DX11 (MG)

I can’t find the document which describes the problem, but here is an example where the half pixel offset was applied:


You should apply the correction to the XNA version, but not to the MonoGame in order to fix it. If it doesn’t fix it, then it’s probably not this problem :slight_smile:


I found an excellent link with information about the half-pixel problem.


this seems to work. But I have to change it a little bit. The offset has to be positive.
Matrix halfPixelOffset = Matrix.CreateTranslation(0.5f, 0.5f, 0);