Click here to Skip to main content
15,794,275 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm trying to make some games in XNA, but I have the following problem:

When I load and show the 3d model on the screen, there is everything ok. You can see it on this picture:
Img1

But when I add a font to my program

C#
font1 = Content.Load<SpriteFont>("Fonts/Fon1");


and show some text

C#
spriteBatch.Begin();
spriteBatch.DrawString(font1, "Speed: ", new Vector2(5, 5), Color.Red);
spriteBatch.End();


I suddenly get that result
Img2

Why is my model in the second image transparent?
Is there any property that somehow makes models transparent when displaying 2D sprites?

Please help.
Posted
Comments
Thomas Barbare 16-Apr-13 15:46pm    
Hi, I think it's a Blend problem but I don't have enough informations :

do you draw the string before or after the 3d model ?
can you add the code for drawing of the 3d model ?
Rddezh 17-Apr-13 7:22am    
I draw the string after drawing model, but if I reverse that, there's no change.
My model drawing code is from that page:
http://msdn.microsoft.com/en-us/library/bb197293%28v=xnagamestudio.31%29.aspx
, but it has some small modifications.
Thomas Barbare 18-Apr-13 12:08pm    
Ok, I tried to find why you got that, take a look at this post : http://stackoverflow.com/a/4180552

It's seems to be the same problem, a render state problem after drawing with spritebatch

I could not find the RenderState property inside GraphicsDevice, but I found this:

C#
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;


on that site: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx[^]

Thanks you very much for your help!
 
Share this answer
 
Comments
Thomas Barbare 18-Apr-13 16:17pm    
Ok, I see this property is not implemented in XNA 4.0
Ok, I tried to find why you got that, take a look at this post : XNA weird 3D painting It's seems to be the same problem, a render state problem after drawing with spritebatch


Change this attribute after using spritebatch

GraphicsDevice.RenderState.DepthBufferEnable = true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900