How can i use 3D view inside WinForms?
Should i use XNA ?
I found this tutorial: http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1
But i dont understand how can i add just ContentLibrary and Content to my WinForms project.
Or is it possbi开发者_如何学Gole to use Scaleform GFx ? for Half2D or 3D ?
There is no way to reference an XNA content project directly from a standard Visual C# project (like you might have with the default WinForms template).
What you must do is create an XNA "Windows Game Library" project (even an empty one) and then use the "Add Content Reference" option on that project to add a reference to your XNA content project. (The template for that is called "Empty Content Project".) And then add a reference to this new Game Library project to your WinForms project.
Alternately there is nothing stopping you creating a "Windows Game" project, and then using "Add Form" - which will add a blank form and the required assembly references. You do have to swap out the XNA template Game1.cs
and Program.cs
for the Program.cs
from a standard WinForms project (or see what the "WinForms 1" sample uses).
For dynamic content loading, check out the "WinForms 2" sample.
I would advise using OpenTK's GL control - OpenTK WinForms control. This is cross-platform, easy to use, and based on OpenGL; which is cross-platform and Mono-compliant. No "hacks" are required to get this to work, and it's a very straightforward way of embedding 3D content in a WinForms container. OpenTK is licensed under the LGPL, meaning you may embed it in commercial applications. OpenTK/OpenGL currently works on Linux, Mac, and Windows and is the easiest method I know of to embed 3D content in a .NET or Mono application. I've tried the XNA in WinForms method, and it ended up being somewhat confusing, and not at all cross-platform. Then they released XNA 4, and my previous XNA apps were not at ALL compatible with the new version. You won't find this problem as often in OpenGL as in DirectX.
Use WPF. You can mix and match the forms. WPF has a winforms container you can drop in a window and make fill it. But you can use WPF out of the box fine with little education - tip = make the window fixed size or resizing will hose your controls. Doing that right is hard.
Then put a wpf panel for a picture where you want the 3d. Cut and paste 3d wpf code from the internet.
There are a few libraries you can use. IDWMaster mentioned OpenTK, which is one option (OpenGL, so your mileage may vary; I'm not a huge fan).
If you'd like to use DirectX, as you tagged the question, there are a few more options. Microsoft used to offer Managed DirectX, which has been deprecated in favor of XNA. SlimDX is a more modern wrapper for the DirectX libraries, exposing most of their functionality (but does have some performance cost). SharpDX is also available, which I belive is supposed to be somewhat faster than SlimDX, but I've not used.
You may also be able to use some of the DirectX APIs directly, using COM interop. C# and .Net support rather good interop with COM components, including native ones. You will have to handle a significant amount of IntPtr
s and may have to do some manual marshaling, but IDirect3DDevice
doesn't have too many methods that would cause trouble (IIRC).
精彩评论