-1

I have searched around the forums on google trying to work this out but I cant. I have done some tutorials on drawing primatives triangles, lines etc.. I now want to draw text, and maybe even textured text/fonts. Totally stuck now, can someone post a snippet that allows me to do this in managed directx for c# please?

user1166981
  • 1,738
  • 8
  • 26
  • 44

2 Answers2

1
using D3D = Microsoft.DirectX.Direct3D; 
private D3D.Font text;
private void InitializeFont() 
{ 
System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, FontStyle.Regular);
 text = new D3D.Font(device, systemfont); 
} 

for more information follow this link:Displaying text using DirectX

KF2
  • 9,887
  • 8
  • 44
  • 77
  • I have actually tried that tutorial, but get an unhandled exception on line: text = new D3D.Font(device, systemfont); I had to change D3D to Direct3D though because there is no D3D reference – user1166981 Jun 23 '12 at 06:14
  • What version of DirectX are you using? – John Davis Jun 23 '12 at 06:16
  • i used DX9 before,your font name is valid? – KF2 Jun 23 '12 at 06:20
  • i exactly use this code:private void InitializeFont() { System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, FontStyle.Regular); text = new D3D.Font(device, systemfont); } – KF2 Jun 23 '12 at 06:21
  • I don't know what caused the error, there isn't any error before debugging/running, just an uncaught exception with no detail – user1166981 Jun 23 '12 at 06:21
  • Where did you get the reference D3D.Font? I have Microsoft.Directx and Microsoft.Directx.Direct3D only – user1166981 Jun 23 '12 at 06:21
  • using D3D = Microsoft.DirectX.Direct3D; private D3D.Font text; – KF2 Jun 23 '12 at 06:26
  • yes, I replaced D3D.Font with Microsoft.DirectX.Direct3D.Font – user1166981 Jun 23 '12 at 06:27
  • witch version of directx u use? – KF2 Jun 23 '12 at 06:28
  • Hi its Directx 9, I made a change and now it no error, but the direct isn't rendering. (none of my other shapes either). – user1166981 Jun 23 '12 at 06:38
  • Could you update your answer with a simple code with this working and maybe I Can see my mistake from that? – user1166981 Jun 23 '12 at 06:41
  • if you want upload your project and send me address,i will try to correct it – KF2 Jun 23 '12 at 06:43
  • try this:http://www.codeproject.com/KB/directx/mdx_tutorial1/mdxtutorial1_src.zip – KF2 Jun 23 '12 at 06:51
  • in protected override void OnPaint(PaintEventArgs e) function in the end line use code"this.Invalidate(); " – KF2 Jun 23 '12 at 06:58
  • and u did not use m_device.BeginScene();?you mast use m_device in onpaint fuction anter "Graphics g = e.Graphics;" – KF2 Jun 23 '12 at 07:03
  • No that didnt help unfortunately, also I forgot to put in m_device.BeginScene();, but that was a typo mistake not related to this error. – user1166981 Jun 23 '12 at 07:03
  • When you use that code are you seeing the text on the screen? Maybe my VS 2010 is not setup correctly? – user1166981 Jun 23 '12 at 07:04
  • if you can upload project file,i will check – KF2 Jun 23 '12 at 07:06
  • can't you just put the code into your project? I Can't really upload the project – user1166981 Jun 23 '12 at 07:07
  • (I really appreciate your help so far, if that is all thank you very much, I need to go to sleep but I think your answer is right, I am making a mistake somehow so I will keep trying to learn and fix it, and tomorrow I will mark your answer as correct.) – user1166981 Jun 23 '12 at 07:21
  • you didnot use " m_device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(0, 0, 255).ToArgb(), 1.0f, 0);"in on paint function – KF2 Jun 23 '12 at 07:38
1

If you're using DirectX 9, the link @irsog posted is a good tutorial, I've used it before and can verify the results. If you use DirectX 10, I recommend the following tutorial:

Note that if you use DirectX 11, you are going to have some trouble. Microsoft removed Direct2D from DirectX 11, so you have to either call DirectX 10 APIs or create you own Font interface. Both options are explored here:

How do you draw text in DirectX 11?

Community
  • 1
  • 1
John Davis
  • 736
  • 6
  • 14
  • How do I find out which one I am using? – user1166981 Jun 23 '12 at 06:20
  • When you added the references to the DLLs, it should tell you the version number. – John Davis Jun 23 '12 at 06:22
  • Ah, my mistake, thats going to be the version number of the particular version of DirectX, so that doesn't get us anywhere... Where did you download DirectX from? Can you give me the URL of the SDK you downloaded? – John Davis Jun 23 '12 at 06:24
  • It was the Feb and June 2010 SDKs I downloaded, but I dont know which one placed the DLLs in the windows folder – user1166981 Jun 23 '12 at 06:25
  • Either way, both of those SDKs are directX 9, so full credit to @irsog for the tutorial link. If you post a new question with some more code, it would be most specific and would probably get more answer :) – John Davis Jun 23 '12 at 06:27
  • ok, so it seems I am maybe putting things in the wrong place :), thanks a lot I will try a fresh project again with no other code and see if I can recreate the result and post a new question. – user1166981 Jun 23 '12 at 06:29