Sign in to follow this  
Modena_au

Windows Forms and DirectX

Recommended Posts

Hello all. I'm hoping to whip up some tools for my latest project in C# and DirectX. What I'd like to be able to do is to create a Direct3D instance inside a window and have standard windows controls along the left hand side and along the bottom. Basically all I really need to know is if I can create a Direct3D instance inside some control, such as a panel. Thanks for your time.

Share this post


Link to post
Share on other sites
Indeed, you can. I'm not entirely sure which controls will work and which won't, though, but I do know for sure that the PictureBox does work, as that's what I've always used (pre-.NET as well as in Windows Forms) when a basic window didn't do the job.

Share this post


Link to post
Share on other sites
Perfect, thanks. I'll have to try that after work. So just to be clear, when creating your Direct3D instance, you simply attach the code to the picture box, as apposed to the window intself? (I'm normally an openGL/SDL guy, but I wanted to give the otherside a try, so what better way than .net/DirectX/C# :)).

Share this post


Link to post
Share on other sites
Hi there Modena_au,
How are you doing?
Sure, when creating the device you just pass it the handle of the control you are attaching it to.

[Example]
I would say the best control to use would be the System.Windows.Forms.Panel.
Here is an example.
[source lang = c#]
device = new Device(0, DeviceType.Hardware, control.Handle, CreateFlags.HardwareVertexProcessing, pparams);



Hope this helps :)

Share this post


Link to post
Share on other sites
Whenver you are specifying the render target (when you vreate the device), just set it to the control (picturebox or whatever)... I think that should do it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sr_Guapo
Whenver you are specifying the render target (when you vreate the device), just set it to the control (picturebox or whatever)... I think that should do it.


sorry friend how can create a device without specified the render target?

Share this post


Link to post
Share on other sites
Quote:
Original post by Say
Quote:
Original post by Sr_Guapo
Whenver you are specifying the render target (when you vreate the device), just set it to the control (picturebox or whatever)... I think that should do it.


sorry friend how can create a device without specified the render target?


Actually, you still specify a render target, you just use whatever control instead. When you create a device in managed DX, you must pass a few things:


D3DDevice = New Device(AdapterNum, device type, render target, flags, Presentation parameters);

Example:
dev = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, picturebox1, flags, pp)


Just change the "render target" parameter to the control you want. I am sure it will work with picture boxes and oanels, but I have no idea with other controls.

Quote:
Original post by Modena_au
Thanks guys. You've made it seem so easy, I'm almost embarrased I had to ask :).


Don't feel bad. DX can be fairly easy to set up and such, but once you start getting into it, there are thousands of functions and things to keep track of. It is impossible to remember every little function call and how to implement every littlething. That is why I love the forums so much. You can either search foir a solution (through google until they fix it [wink]) or ask yourself.

Share this post


Link to post
Share on other sites
Well... I'm back with more questions already :S
I have this code:

PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Software, pnlRender, CreateFlags.SoftwareVertexProcessing, presentParams);


And it's throwing a DirectXException when calling the Device constructor. I've trying Software, hardware and NullRefernce as Device types and both software and hardware vertex processing for the create flags. So I'm wondering, is there anything special I have to do to prepare the pnl (other than calling the constructor and placing it) or is the problem in my presentParams? Or the equally plossible third option, I'm totally missing the problem here :D.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this