[Solved]VertexPositionTexture weird lines on textures

VertexPositionTexture weird lines on drawn squares with textures

Try setting the PointClamp sampler state.

Can you throw me example :slight_smile: on it.
Iam going crazy.

Here is my code to set position and texures coords

Setting effects and so on


One way is to directly set it before drawing:
graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

This make it worse

What does your shader look like?

I don’t use custom shaders.
Its basic effect cuz I use Linux.

Woho I fixed it by changeing to
graphicsDevice.SamplerStates[0] = SamplerState.PointWrap;

:rainbow: Perfection :rainbow:

1 Like

You just needed to set point. default is linear which performs texturefiltering on nearby texels.

A little tip create the sampler state at the class scope and reuse it
Recreating it and setting it makes quite a bit of garbage collections.

So you put this at the top of the class.

        public static SamplerState SS_PointBorder= new SamplerState() { Filter = TextureFilter.Point, AddressU = TextureAddressMode.Border, AddressV = TextureAddressMode.Border };
        public static SamplerState SS_PointClamp = new SamplerState() { Filter = TextureFilter.Point, AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp };
        public static SamplerState SS_PointWrap = new SamplerState() { Filter = TextureFilter.Point, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap };
        public static SamplerState SS_PointMirror = new SamplerState() { Filter = TextureFilter.Point, AddressU = TextureAddressMode.Mirror, AddressV = TextureAddressMode.Mirror };

You can then set this in spriteBatch,Begin(,SS_PointWrap, ); and garbage collections go bye bye;
Or here m pretty sure this will avoid collections either way
graphicsDevice.SamplerStates[0] = SS_PointWrap;

The static readonly SamplerState fields are already cached. His use-case here won’t make new allocations.

Ah i didn’t realize that so used to doing this with the other states i jumped the gun.
Mirror is missing that probably should be in there.

namespace Microsoft.Xna.Framework.Graphics
    public class SamplerState : GraphicsResource
        public static readonly SamplerState AnisotropicClamp;
        public static readonly SamplerState AnisotropicWrap;
        public static readonly SamplerState LinearClamp;
        public static readonly SamplerState LinearWrap;
        public static readonly SamplerState PointClamp;
        public static readonly SamplerState PointWrap;

        public SamplerState();

        public float MipMapLevelOfDetailBias { get; set; }
        public int MaxMipLevel { get; set; }
        public int MaxAnisotropy { get; set; }
        public TextureFilter Filter { get; set; }
        public TextureAddressMode AddressU { get; set; }
        public TextureAddressMode AddressW { get; set; }
        public TextureAddressMode AddressV { get; set; }
        public CompareFunction ComparisonFunction { get; set; }
        public Color BorderColor { get; set; }
        public TextureFilterMode FilterMode { get; set; }

        protected override void Dispose(bool disposing);