Sign in to follow this  
billconan

can i create a device with picturebox? (c#)

Recommended Posts

hi guys, can i render my scene into a picturebox? i tried with this code, but it doesn't work. device = new Microsoft.DirectX.Direct3D.Device(0,Microsoft.DirectX.Direct3D.DeviceType.Hardware,this.PictureBox, CreateFlags.SoftwareVertexProcessing, presentParams); it works perfectly with winform. i don't know why? thanks

Share this post


Link to post
Share on other sites
What did you set in your PresentParameters class? If you set the DeviceWindow to null, it uses the focus window, so you probably should set that as well.

Share this post


Link to post
Share on other sites
What sometimes happens is that as a parameter you need to explicity pass the handle of the control as an argument to the device constructor.


device = new Microsoft.DirectX.Direct3D.Device(0,Microsoft.DirectX.Direct3D.DeviceType.Hardware,PictureBox.Handle,CreateFlags.SoftwareVertexProcessing,presentParams);



PS: Rendering to a Panel control is what most people use.

I hope this helps,
Take care.

Share this post


Link to post
Share on other sites
look did u load the initialization of the pcturebox { InitializeComponents } maybe u have forgotten to do this and the error u are having is because u didnot create an instance from the picturebox . hope this will help

Share this post


Link to post
Share on other sites
this is the code which doesn't work. i use picturebox because i've heard that only form and picturebox can hold the directx device. guess i should change it to panel now.

PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.DeviceWindow=this.mainForm.devicePictureBox;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
device = new Microsoft.DirectX.Direct3D.Device(0,Microsoft.DirectX.Direct3D.DeviceType.Hardware,this.mainForm.devicePictureBox.Handle,
CreateFlags.SoftwareVertexProcessing, presentParams); //Create a device



[Edited by - billconan on November 6, 2005 4:22:23 AM]

Share this post


Link to post
Share on other sites
It's generally a good idea to work with a nice depth/stencil format such as D24S8
This caters for a Depth buffer of 24 bits and a stencil buffer of 8 bits. Also you might want to disable lighting if you don't have any lights in your scene.

i.e.
Device.RenderState.Lighting = false;

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
hi thanks
some screenshots, i changed the depth to d24s8, still the same.

this is the scene that i rendered with form:


and this is the current scene with the panel:



my scene has a light.


PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.DeviceWindow=this.mainForm.devicePanel;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;
device = new Microsoft.DirectX.Direct3D.Device(0,Microsoft.DirectX.Direct3D.DeviceType.Hardware,this.mainForm.devicePanel,
CreateFlags.SoftwareVertexProcessing, presentParams); //Create a device

Share this post


Link to post
Share on other sites
i made it! i changed the this.mainForm.devicePanel to this.mainForm.devicePanel.Handle and it works! thanks guys!
the quality is kinda low now, the lines became wider and rendering result is coarse. :(

Share this post


Link to post
Share on other sites
Would it be possible to see the code you a rendering your mesh with as I cannot really see anything wrong with the initialization of your device. It seems fine although I did comment earlier that it might be beneficial to explicitly pass the handle of the control you want to render to, to the device's constructor.

i.e.

device = new Device(0, DeviceType.Hardware, devicePanel.Handle, CreateFlags.SoftwareVertexProcessing, presentParams);




Some checks,
1) Make sure you are calling the DrawSubset() method of your mesh.
2) Make sure you are setting your lights and enabling them
3) Check if you are setting your materials and textures
4) Make sure you are setting the correct View and Projection transformation matrices.

Other than that I will need to see your rendering code to further help you.

I hope this helps.
Take care.

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