Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to disable texture filtering (since I'm making a retro-style game where it looks bad if a texture gets filtered like that), but since I'm on XNA 3.1 there seems to be no option to set a SamplerState with SpriteBatch.Begin or anything. Is it possible to do this?

share|improve this question
Why don't you update at least to 3.1? – r2d2rigo Nov 15 '11 at 0:46
Sorry, i forgot i was actually on 3.1 >.> – RCIX Nov 15 '11 at 0:54
I'd strongly suggest moving to XNA 4.0. – Andrew Russell Nov 15 '11 at 3:09
You should also update the question's title to 3.1 so it's clear. – Richard Marskell - Drackir Nov 15 '11 at 20:09
@AndrewRussel: At this point, I have a nontrivial amount of shader interaction code written, and IIRC it's a pain to convert it. Moreover, I don't even really have room on my HDD right now for VS 2010 :P – RCIX Nov 16 '11 at 23:34
up vote 4 down vote accepted

The behaviour of SpriteBatch in XNA before 4.0 is rather ugly. Note that this answer only applies to XNA pre-4.0.

This is a list of render states that SpriteBatch controls (pre-4.0).

When SpriteBatch applies those settings depends on the SpriteSortMode parameter. The only reliable way to modify those settings is with SpriteSortMode.Immediate.

The way this works that, in immediate mode, SpriteBatch will set its render state when you call Begin. Immediately after calling Begin you can set your own render state, before you call SpriteBatch.Draw.

(States that SpriteBatch does not control can be set outside of the Begin/End block.)

The states you want to change (as r2d2rigo mentioned) are:

GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;
share|improve this answer


GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;

before using SpriteBatch.Begin. And remember to restore the values after SpriteBatch.End.

share|improve this answer
Not quite right. See my answer for a description of when to set those states. – Andrew Russell Nov 15 '11 at 3:22

This is very possible. You can use a custom shader with spritebatch. The source to the default spritebatch shader is available from the XNA 'education catalog'. What you will need to do is get this shader and change the texture filtering in the shader from linear to point filtering, and then use your new version of the shader with spritebatch. To use it with spritebatch, call spritebatch.Begin, but set the sprite sort mode to immediate (This effectively means no batching). Then, apply the correct technique on your new effect. Then draw your sprites. Spritebatch will draw them immediately with whatever effect is currently applied.

IIRC using a custom shader with spritebatch is far simpler in XNA 4.0.

share|improve this answer
While this will actually work, compiling a custom shader is a bit of overkill when you can just change the render state directly. – Andrew Russell Nov 15 '11 at 3:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.