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'm looking for a way to add a sprite using a particular logic operation (like XOR). I can't find anything on Google and I'm not sure where to look in the documentation.

I've looked into SpriteBatch.Begin(...) and its Draw method and several options in the GraphicsDevice class, but I'm not recognizing anything capable of this. I'm still pretty new to XNA so I may just not have recognized the terminology to do this.

share|improve this question
Are you targeting XBox/PC or WP7 platforms? – r2d2rigo Oct 15 '11 at 22:27
PC right now. If I ever expand, I'd probably only expand to the xbox because I do not have a Windows Phone. – Corey Ogburn Oct 16 '11 at 3:38

The GraphicsDevice.RasterizerState property is how you alter raster settings.

There are three default states built in but I don't believe the RasterizerState is what you are looking for.


I'm not sure what you mean by xor sprites together. However, from the below comment I'm assuming you want to use an overlay for a crosshair. If you do want to use an overlay you could use alter the BlendState as Jonathan Dickinson pointed out.

Aside from just another tool in the toolbelt, I'm looking into how to make a crosshair for targeting. An inverted crosshair (in my experience/opinion) is the best crosshair

enter image description here

Just set the below as the BlendState in SpriteBatch.Begin(). Also worth noting is that if the SortMode is SpriteSortMode.Immediate you can alter the all of the GraphicsDevice's properties without calling Spritebatch.Begin again.

        GraphicsDevice.BlendState = new BlendState {

            ColorSourceBlend = Blend.Zero,
            ColorDestinationBlend = Blend.InverseSourceColor,

            AlphaSourceBlend = Blend.Zero,
            AlphaDestinationBlend = Blend.InverseSourceColor


enter image description here

share|improve this answer
I'll try this when I get a chance. – Corey Ogburn Feb 14 '12 at 16:37

One option may be defining a new BlendState...and choose the right BlendFunction and Factors to get the xor operation. I'm not sure it can be done, but it is the easier way and should be your first option.

The second option is using a HLSL shader and rendertargets.

1. You draw to rendertargetA you sprites
2. if you want to do a xor operation.. 
     3. you assign the texture source in your shader from rendertargetA
     4. you draw with your xor shader to rendertargetB  
     5. exchange rendertarget reference, RendertargetA is now B, and viceversa
6. Draw from your rendertarget A to the backbuffer.

Or something similar... :)
share|improve this answer
everyway xor operations with textures has not much sense in modern hardware, because it is expected to be a full redraw every frame... ¿are you sure you need this operation? – Blau Oct 16 '11 at 0:46
Aside from just another tool in the toolbelt, I'm looking into how to make a crosshair for targeting. An inverted crosshair (in my experience/opinion) is the best crosshair. – Corey Ogburn Oct 16 '11 at 3:42
aaah... ok... then you should choose the BlendState way... if not accurate, i'm sure you can get a similar effect. – Blau Oct 16 '11 at 10:25
@CoreyOgburn you could try (source x Blend.Zero) + (destination x Blend.InverseSourceColor) - i.e. set up a BlendState as such. – Jonathan Dickinson Oct 17 '11 at 9:48

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.