Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
2  
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

3 Answers 3

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

Call

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
1  
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

 
discard

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.