• Advertisement
Sign in to follow this  

sample code for DirectX with WPF?

This topic is 732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a WPF app that needs to render thousands of 3D lines per second.  (N.B just lines -  I don't need shading, lighting, surfaces, etc)

I think the best way to do this with Direct3D/DirectX is using the D3DImage class  to avoid airspace problems with my other WPF controls.    I'm trying to find a working example on the web that I can download and learn from but I haven't had any luck.

I'm trying to avoid using third-party solutions because many of them are abandoned or deprecated, e.g., XNA and SlimDX.

Could someone please suggest some sample code that will help me get started on this?

Also, besides this group, are there other good active forums for this topic?   (StackOverflow does not seem to be a very fertile source of DirectX/WPF interop advice, and Google's DirectXDev group seems to average about one posting a month)

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement

I'm trying to avoid using third-party solutions because many of them are abandoned or deprecated, e.g., XNA and SlimDX.

 

They still work, and are simple and easy to use. Much easier than writing your own thin wrapper around the d3dapi simply to draw lines. As long as you can grab a HWND to whichever WPF panel you want to draw to, there shouldn't be much of an issue. XNA and WPF also use the .NET framework, simplifying things even further, no marsherling/Interop required.

Edited by ExErvus

Share this post


Link to post
Share on other sites

have a WPF app that needs to render thousands of 3D lines per second.

Just out of curiosity, have you verified that WPF alone cannot handle this fast enough, before trying something else? Using low-level primitives such as paths and geometries should be fast enough for most uses. Since WPF uses DirectX internally, I would go with DirectX interop only if everything else fails. In addition to this, WPF has some basic 3D support, which might also suffice, if you have relatively modest needs.

Edited by vanka78bg

Share this post


Link to post
Share on other sites

 


I'm trying to avoid using third-party solutions because many of them are abandoned or deprecated, e.g., XNA and SlimDX.

 

They still work, and are simple and easy to use. Much easier than writing your own thin wrapper around the d3dapi simply to draw lines. As long as you can grab a HWND to whichever WPF panel you want to draw to, there shouldn't be much of an issue. XNA and WPF also use the .NET framework, simplifying things even further, no marsherling/Interop required.

 

No, just grabbing an HWND doesn't solve airspace issues.    That's why WPF has the D3DImage class.  

 

Also, it's not clear whether they still work - Microsoft has deprecated large parts of the DirectX family so I'm looking for a working, buld-able sample to confirm they still work.   Can you suggest one?  I've downloaded several from places like GitHub and CodeProject but couldn't get them to build with VS2013.

Edited by plnelson

Share this post


Link to post
Share on other sites

 


have a WPF app that needs to render thousands of 3D lines per second.

Just out of curiosity, have you verified that WPF alone cannot handle this fast enough, before trying something else?

WPF doesn't have a 3D line drawing primitive.  It only knows from 3D shaded, lit triangles.  If you want a 3D line in WPF you have to construct it out of polyhedrons, and yes I have confirmed that that is incredibly slow when you're trying to rotate, say, 10,000 such "lines" made out of polyhedrons, not to metion avoiding artifacts where said "lines" meet at the endpoints.

Edited by plnelson

Share this post


Link to post
Share on other sites

I have confirmed that that is incredibly slow

OK, I was just trying to rule out the most straightforward approach first. Since WPF does not suit your needs, I would recommend using SharpDX. It is actively developed and used in many popular projects, such as MonoGame, Xenko etc., so it is very unlikely to be abandoned soon.

Edited by vanka78bg

Share this post


Link to post
Share on other sites

 


I have confirmed that that is incredibly slow

OK, I was just trying to rule out the most straightforward approach first. Since WPF does not suit your needs, I would recommend using SharpDX. It is actively developed and used in many popular projects, such as MonoGame, Xenko etc., so it is very unlikely to be abandoned soon.

 

Thanks.  So I downloaded SharpDX and built and ran some of the samples in its "Desktop" folder but none of those used WPF.  

As I said in the OP, our application uses WPF but we need the graphics to use DirectX/Direct3D.  The only SharpDX examples in their "Deskrop" folder that seem to use WPF are some audio examples, not 3D graphics examples.

Can you suggest some SharpDX samples that show interop with WPF?

Share this post


Link to post
Share on other sites


If your looking for an example with SharpDx and Wpf this link would be really helpful.

This sample is somewhat outdated, but it demonstrates what you need - using SharpDX with WPF and D3DImage. I tried to avoid duplicating information from the posts of other people. If you have difficulties making the sample work with the latest version of SharpDX, I can offer a helpful hand.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement