3D in WinForms?
Asked Answered
S

4

6

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 possbile to use Scaleform GFx ? for Half2D or 3D ?

Spiritualist answered 18/7, 2011 at 16:26 Comment(3)
I had tried this with a few others back in XNA 2.0 and the general consensus was that it wasn't possible to do and still have working input in WinForms because XNA hooked it and didn't pass the data or something. I am interested to see if this has changed with 4.0.Wideopen
What kind of 3D? WPF could be another option.Bicarbonate
@Xeon06: it's fine these days.Heisler
R
5

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.

Rauscher answered 19/7, 2011 at 2:28 Comment(0)
H
9

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.

Heisler answered 19/7, 2011 at 2:10 Comment(0)
P
8

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.

Peeress answered 18/7, 2011 at 16:32 Comment(7)
Which 3D models extensions can i use with this?Spiritualist
There is a OBJ loader on OpenTK's website, and I made a modified ObjLoader with built-in collision detection that I could upload if you like. I'm sure there's other formats that you could also find support for somewhere in their forums.Peeress
I've got to go now, but I'll post my ObjLoader source code sometime around 6:00PM (Central Time, US and Canada) today.Peeress
Very intresting :) i'm trying to play with it right away i whould really like to see you ObjLoader :) thxSpiritualist
You won't find this problem as often in OpenGL as in DirectX It's not that DirectX broke back compt, it was that the XNA team broke it. The underlying COM+ structure of DirectX was unaffected.Draw
@Draw I know XNA broke it, DirectX still rocks. but you have an example on how to use it in Windows Forms?Spiritualist
@Spiritualist I have a project at home in xna 3.1 with a reusable xna panel you can drag and drop onto windows forms. I can throw it on pastebin later tonight if you'd like.Draw
R
5

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.

Rauscher answered 19/7, 2011 at 2:28 Comment(0)
S
1

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).

Save answered 19/7, 2011 at 2:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.