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 am working on a game in XNA 4.0 that has been entirely in 3D so far but now I want to incorporate a HUD.

I have tried doing a simple test using spriteBatch as such:

spriteBatch.Begin();
spriteBatch.Draw(Player.Texture, new Rectangle(0, GameConstants.GraphicsDevice.Viewport.Height - 50, 50, 50), Color.White);
spriteBatch.End();

This works fine and the test texture shows as a rectangle in the correct position but the 3d World behind seems to have a sort of "haze" over the top which looks like the drawn "Player.Texture" has been put all over the viewport but at an alpha of like 0.1f.

I googled around and have a reset() function to change some of the GraphicsDevice properties back after drawing the SpriteBatch but nothing has changed and I haven't seen anyone else with this problem.

I thought it would be that SpriteBatch changes the blendmode to additive but in my reset() function I set the blendmode to opaque so I have no idea where this strange effect is coming from, it looks like I've ran some post-processing on the whole scene.

If I change the Player.Texture that is drawn in the SpriteBatch then the "haze" changes to look like the new texture so it is definitely to do with that.

Are there any other GraphicsDevice propterties I should check to change back?

Edit

Okay, I have just realised the "haze" over the top is from the SkySphere texture, I am using the MSDN skysphere shader from this tutorial.

So when I comment out the SkySphere code, the spritebatch and 3d drawing looks completely fine, but this leaves me with the problem that I can't have a SkySphere anymore.

Is there some reason why the skysphere is sort of drawn over the scene translucently rather than behind the 3D after I use a SpriteBatch? As I said before, it kind of looks like additive blending.

Below are 2 screenshots, the top is with spritebatch and no skysphere, below is with spritebatch and skysphere where I am having problems. I have cropped the images down to save upload (my internet is pretty slow at the moment) and I've changed the area of the scene in the 2nd image to show more clearly what it looks like. As I move around the scene with the camera the "haze" overlay stays in the same place exactly as how the SkySphere works, as in not taking into account the world matrix.

Screenshot 1 Screenshot 2

share|improve this question
    
A screenshot would help. –  Tetrad Jan 8 '12 at 2:54
    
Sorry, I've added links to screenshots now but I can only have 2 hyperlinks so there are only 2 images, also I've narrowed the problem down to the SkySphere shader. Thanks. –  user319256 Jan 8 '12 at 3:15
    
@user319256 - I know you said you tried changing some back, but have you taken a look at blogs.msdn.com/b/shawnhar/archive/2010/06/18/…? Also, did you draw 3D first, or 2D first? This can affect where you should place your reset function. –  DMan Jan 8 '12 at 4:04
3  
My psychic powers say that your reset function clears the depth buffer, and you're drawing like this : World, Hud, Reset, Sky. –  Blecki Jan 8 '12 at 16:08
    
Ah yes, I didn't think about the order in which the skysphere and 3d and spritebatch was rendered so even though I reset the settings linked after drawing the spritebatch the skysphere then set some other values which needed to be reset. Thanks for the help! –  user319256 Jan 8 '12 at 16:28
show 1 more comment

1 Answer 1

It looks like you're drawing your skysphere after your HUD. You should draw the skysphere after drawing the world (the depth buffer will save you a lot of overdraw), and draw the hud last.

share|improve this answer
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.