Click here to Skip to main content
12,502,578 members (55,302 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# XNA4.0
I have problem when I draw a string in XNA 4.0 3D.I known problem is spriteBatch.Begin(). But I don't know how to solve it.
protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DeepSkyBlue);
            //Draw string 
            spriteBatch.Begin();
            spriteBatch.DrawString(fontArial, "Demotesting", new Vector2(100, 100), Color.Red);
            spriteBatch.End();
            //Draw Models Ship
            ship.Draw();
 
            base.Draw(gameTime);
 
        }
Before draw string:
<img src="http://nq1.upanh.com/b4.s32.d1/6c6ce19bded8d054341ce45e17426c51_49358001.before.png" />
After draw string
<img src="http://nq2.upanh.com/b6.s30.d2/9ff7c3c009215348b06a53c5a067d282_49358002.after.png" />

Can help me?

P/S:Sorry because bad english!
Posted 22-Sep-12 0:48am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You need to do two things.
First. draw 3D before 2D
protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DeepSkyBlue);
           //Reset Graphics Device here
#region 3D
            //Draw Models Ship
            ship.Draw();
#endregion
           
#region 2D
            //Draw string 
            spriteBatch.Begin();
            spriteBatch.DrawString(fontArial, "Demotesting", new Vector2(100, 100), Color.Red);
            spriteBatch.End();
#endregion          
  base.Draw(gameTime);
 
        }
Second you should ensure that you are resetting the graphics devise to the default for model rendering See Here[^]
  Permalink  
Comments
haitrieu749 18-Oct-12 14:11pm
   
Hi ely_bob!! Can you help me about follow question?? I have tired about this ! Thanks very much!!
http://www.codeproject.com/Questions/479362/ShadowplusEffectplusinplusXNA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Thanks ely_bob for your answer! But I think
GraphicsDevice.SamplerStates [0] = SamplerState.AnisotropicWrap;
is better than
GraphicsDevice.SamplerStates [0] = SamplerState.LinearClamp; 
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100