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

Started by
11 comments, last by Armadon 18 years, 5 months ago
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
Advertisement
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.
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
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]
hi guys, i changed it to panel, it seems working, but still weird, cause the model of the scene is missing, and i get only the background rendered.
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.
@billconan: Your post contained code that was too wide. I changed your code tags into source tags. Please read this.

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
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. :(

This topic is closed to new replies.

Advertisement