3D in WinForms?

前端 未结 4 1935
别那么骄傲
别那么骄傲 2021-01-02 22:05

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

相关标签:
4条回答
  • 2021-01-02 22:43

    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.

    0 讨论(0)
  • 2021-01-02 22:56

    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.

    0 讨论(0)
  • 2021-01-02 23:00

    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.

    0 讨论(0)
  • 2021-01-02 23:00

    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 IntPtrs and may have to do some manual marshaling, but IDirect3DDevice doesn't have too many methods that would cause trouble (IIRC).

    0 讨论(0)
提交回复
热议问题