0
\$\begingroup\$

I'm looking for help fixing a small problem that I have with my XNA game project.

I currently have:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
            null, null, null, null, camera.ViewMatrix);
        spriteBatch.Draw(Stone, TestPosition, Color.White);
        spriteBatch.Draw(Person, playerPosition, Color.White);
        spriteBatch.End();

and

spriteBatch.Begin(SpriteSortMode.Deferred,
              null, SamplerState.LinearWrap, null, null);
        spriteBatch.Draw(Grass, grassPosition,
             new Rectangle(0, 0, Grass.Width * 60, Grass.Height * 1),
             Color.White);
        spriteBatch.Draw(Stone, StonePosition,
             new Rectangle(0, 0, Stone.Width * 60, Stone.Height * 10),
             Color.White);

        spriteBatch.End();

I am looking to combine these two spriteBatch so that the stone and grass in the second spriteBatch will be affected by the viewmatrix.

I have tried:

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend,
                SamplerState.LinearWrap, null, null, null, camera.ViewMatrix);
            spriteBatch.Draw(Grass, grassPosition,
                 new Rectangle(0, 0, Grass.Width * 60, Grass.Height * 1),
                 Color.White);
            spriteBatch.Draw(Stone, StonePosition,
                 new Rectangle(0, 0, Stone.Width * 60, Stone.Height * 10),
                 Color.White);
            spriteBatch.Draw(Stone, TestPosition, Color.White);
            spriteBatch.Draw(Person, playerPosition, Color.White);
            spriteBatch.End();

However when I go to run the code, I get the following error:

XNA Framework Reach profile requires TextureAddressMode to be Clamp when using texture sizes that are not powers of two.

I hope that someone can help me achieve this, Thank You.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The error indicates that if you are using textures that are not powers of 2 (128x128, 256x256, etc), that you must set the SamplerState parameter of SpriteBatch.Begin to SamplerState.LinearClamp instead of SamplerState.LinearWrap.

Judging from your code it looks like Grass and Stone are powers of 2, but the Person is not.

To fix the problem you'll need to either change the Person texture to a power of two, use SamplerState.LinearClamp for everything you listed, or draw the Person texture with its own SpriteBatch.Begin and End using Sampler.LinearClamp and the rest that are powers of two using LinearWrap.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Or change from Reach to HiDef profile in the property settings of the project. \$\endgroup\$ Commented Oct 1, 2014 at 13:32
  • \$\begingroup\$ Thanks, it's working great and thank you for your fast response. \$\endgroup\$ Commented Oct 1, 2014 at 22:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.