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'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
add comment

2 Answers 2

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.

RasterizerState.CullCounterClockwise
RasterizerState.CullClockwise
RasterizerState.CullNone

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
add comment

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.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.blendstate.alphablendfunction.aspx

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
2  
@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
add comment

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.