简体   繁体   中英

Clamping TextureAddressMode in XNA

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.

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;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM