I have a problem using DrawUserPrimitives for my very first monogame project. I am trying to draw multiple tiles that should look like a terrain. And it works...well somehow. This is how it looks like:
My terrain -_-. Sorry, I cant post it directly because of 0 reputation
Every single tile looks like this:
Single tile with a white border
As you can see every tile has a 1px white border. This is the only source for white lines, i guess.
Problem: I dont like these white horizontal lines (Not the border around every tile, these are ok).
So my question is: How to get rid of them. What is wrong with my code?
Every cell is created by that code:
// [ ][ ][ ]
// [ ][ ][ ]
// [x ][ ][ ]
primitiveList[0].Position = new Vector3(0 + startpos.X, 0, 0 + startpos.Z);
primitiveList[0].TextureCoordinate.X = 0;
primitiveList[0].TextureCoordinate.Y = 1;
// [ ][ ][ ]
// [ ][ ][ ]
// [ ][ ][x]
primitiveList[1].Position = new Vector3(1 + startpos.X, 0, 0 + startpos.Z);
primitiveList[1].TextureCoordinate.X = 1;
primitiveList[1].TextureCoordinate.Y = 1;
// [ ][ ][x ]
// [ ][ ][ ]
// [ ][ ][ ]
primitiveList[2].Position = new Vector3(1 + startpos.X, 0, 1 + startpos.Z);
primitiveList[2].TextureCoordinate.X = 1;
primitiveList[2].TextureCoordinate.Y = 0;
// Ergibt:
// [ ][ ][x]
// [ ][ ][ ]
// [x][ ][x]
// [ ][ ][x]
// [ ][ ][ ]
// [ ][ ][ ]
primitiveList[3].Position = new Vector3(1 + startpos.X, 0, 1 + startpos.Z);
primitiveList[3].TextureCoordinate.X = 1;
primitiveList[3].TextureCoordinate.Y = 0;
// [x][ ][ ]
// [ ][ ][ ]
// [ ][ ][ ]
primitiveList[4].Position = new Vector3(0 + startpos.X, 0, 1 + startpos.Z);
primitiveList[4].TextureCoordinate.X = 0;
primitiveList[4].TextureCoordinate.Y = 0;
// [ ][ ][ ]
// [ ][ ][ ]
// [x][ ][ ]
primitiveList[5].Position = new Vector3(0 + startpos.X, 0, 0 + startpos.Z);
primitiveList[4].TextureCoordinate.X = 0;
primitiveList[4].TextureCoordinate.Y = 1;
and the drawing code:
_graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
}
_graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, _terrainManager.TerrainVertices, 0, _terrainManager.TerrainVertices.Length / 3,VertexPositionNormalTexture.VertexDeclaration);
The setup for the effect:
if (effect == null)
{
effect = new BasicEffect(_graphics.GraphicsDevice);
/*effect.CurrentTechnique = effect.Techniques ["BasicEffect_PixelLighting_Texture"];
*/
effect.EnableDefaultLighting();
effect.TextureEnabled = true;
effect.Texture = _grassGrid;
var state = new RasterizerState { MultiSampleAntiAlias = true };
state.DepthBias = 100.0f;
effect.GraphicsDevice.RasterizerState = state;
/*foreach (var lol in effect.Techniques)
{
Console.WriteLine (lol.Name);
}*/
//effect.CurrentTechnique = effect.Techniques ["BasicEffect_Texture"];
_graphics.PreferMultiSampling = true;
_graphics.GraphicsDevice.PresentationParameters.MultiSampleCount = 4;
//_graphics.ApplyChanges ();
I just can't find out where the problem is. At least after 3 hours of googling / try and error. I also tried some multisampling to include. But that has absolutely no effect. I don't know enough to just guess what could be wrong here. I dont need an solution (though that would be fine :)). A hint would be awesome. Thanks for your help in advance!
You have a typo here:
// [ ][ ][ ]
// [ ][ ][ ]
// [x][ ][ ]
primitiveList[5].Position = new Vector3(0 + startpos.X, 0, 0 + startpos.Z);
primitiveList[4].TextureCoordinate.X = 0;
primitiveList[4].TextureCoordinate.Y = 1;
The indices of primitiveList
should all be 5.
Your texture coordinates got messed up, that causes the random white lines.