SlimDX viewports in WPF controls

非 Y 不嫁゛ 提交于 2019-12-23 08:16:46

问题


I am transitioning from WinForms/XNA to WPF/SlimDX because:

  • a) all of the benefits of WPF over WinForms (but learning curve = ouch!)
  • b) I would like to have multiple SlimDX viewports attached to Panels. XNA has 1 "game" screen.
  • c, last and least) DirectX 10 support

All of my previous XNA code is in C#. I am having trouble figuring out how to port this over to SlimDX and WPF on a high level. I have searched like crazy. The closest I have found are:

1) http://www.gamedev.net/community/forums/topic.asp?topic_id=507941 Many articles point to this discussion, however it is incomplete and I can't figure out the XAML, and I get device errors after attaching all of the _slimDXDevice and Window1 events that were left out.

2) http://www.codeproject.com/KB/WPF/D3DImage.aspx This article assumes the user is porting C++. I am porting XNA code which is very close to MDX code.

If I could get to the point where I have a WPF form with a custom SlimDX driven viewport that was just a blue box, I could go from there. In XNA I rendered many separate RenderTargets and placed them all over the screen, now I want to attach them to controls. But first, just 1 blue box! :D

Any ideas? I feel that this is either simple or that there's some "cookie cutter" code that I'm missing. Greatly appreciated!


回答1:


You can look at the sample now. It's just been checked in to our repository, so you'll need to use SVN to get it (or wait until we ship the Feb 2010 release):

http://code.google.com/p/slimdx/source/detail?r=1356




回答2:


D3DImage is the class you want to use. Even though the codeproject tutorial is C++, it is very applicable to SlimDX and WPF.

All you have to do with your SlimDX, is run your code normally, but DO NOT run a Present(...) on your device or swap chain. At the point where you would put a Present(...), do a D3DImage.SetBackBuffer(...) and send your SlimDX surface's ComPointer property to it. Then do D3DImage.AddDirect(...) and you now have D3D composited in WPF.

Also, make sure you create a IDirect3DDevice9Ex or else your performance will be terrible in anything but XP!




回答3:


I recently was messing around with D3DImage and SlimDX and didn't find it too difficult to get it working (with DirextX9). I have some code at my home pc that I'll post later, but it's pretty similar to the code in the links provided.

I was never able to get it working with a higher version of directx though. Jeremiah has a nice blog post about using a directx9 device as a link between directx 10/11/d2d and the D3DImage, but I couldn't get it working with Slimdx. I didn't put a whole lot of effort into though as directx9 did what I needed it to do and I kind of wanted it to work on XP.



来源:https://stackoverflow.com/questions/2246386/slimdx-viewports-in-wpf-controls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!