Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clamping TextureAddressMode in XNA

Tags:

c#

xna

xna-4.0

I've been working on implementing a 2D lighting system in XNA, and I've gotten the system to work--as long as my window's dimensions are powers of two. Otherwise, the program will fail at this line:

GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, Vertices, 0, 2);

The exception states that "XNA Framework Reach profile requires TextureAddressMode to be Clamp when using texture sizes that are not powers of two," and every attempt that I've made to slve this problem has failed--the most common solution I've found on the internet is to put the line GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; directly above the line above, but that hasn't solved my problem.

I apologize if I've left out any information that could be necessary to solve this; I'll be more than happy to provide more as needed.

like image 842
bionicOnion Avatar asked Dec 03 '25 16:12

bionicOnion


1 Answers

Isn't this the same question you asked before?

In your HLSL look for the line that declares the sampler that the pixel shader is using.

You can set the address mode to clamp in this line.

SamplerState somethingLikeThis {
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};
like image 128
Andy Avatar answered Dec 07 '25 16:12

Andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!