Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectX initilization in C#

Started by Ksingh30 Aug 6, 2006 at 9:18 PM 2 replies 1.4k views
Original Post
Ksingh30
Ksingh30
Hi, Im trying to initilize Direct3D in C# and was getting someerrors which I couldnt figure out what was causing them All the errors are with this method

public void InitDevice()
{
   Device device;
            PresentParameters presentParams = new PresentParameters();
           
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;
            device = new Device(0, DeviceType.Hardware, this,
                                CreateFlags.SoftwareVertexProcessing,            presentParams);
}

The best overloaded method match for 'Microsoft.DirectX.Direct3D.Device.Device(int, Microsoft.DirectX.Direct3D.DeviceType, System.IntPtr, Microsoft.DirectX.Direct3D.CreateFlags, params Microsoft.DirectX.Direct3D.PresentParameters[])' has some invalid arguments C:\Documents and Settings\Kevin\Desktop\WindowsApplication1\WindowsApplication1\Program.cs 17 Argument '5': cannot convert from 'Microsoft.DirectX.Direct3D.PresentParameters' to 'Microsoft.DirectX.Direct3D.PresentParameters[]' C:\Documents and Settings\Kevin\Desktop\WindowsApplication1\WindowsApplication1\Program.cs 18 Argument '3': cannot convert from 'WindowsApplication1.Program' to 'System.IntPtr' C:\Documents and Settings\Kevin\Desktop\WindowsApplication1\WindowsApplication1\Program.cs 17
qingrui
qingrui
Quote:
Original post by Ksingh30
public void InitDevice(){   Device device;            PresentParameters presentParams = new PresentParameters();                       presentParams.Windowed = true;            presentParams.SwapEffect = SwapEffect.Discard;            device = new Device(0, DeviceType.Hardware, this,                                CreateFlags.SoftwareVertexProcessing,            presentParams);}



The last parameter is an array of PresentParameters, though normally we only use one. So you should pass "new PresentParameters[] {presentParams}".

The third parameter requires a Form object, and can be null if you use only windowed mode. But if it's null, then you have to set presentParams.DeviceWindow to some control on form.
Ksingh30
Ksingh30
sweet thanks so much.
Armadon
Armadon
Just as a side note,
When creating a device, pass it some default parameters.
This includes the width and height of the backbuffer, if the device should be windowed or not, and last but not least the swapeffect.

For Example
PresentParameters pparams = new PresentParameters();pparams.BackBufferWidth = deviceSettings.CurrentDisplayMode.Width;pparams.BackBufferHeight = deviceSettings.CurrentDisplayMode.Height;pparams.Windowed = deviceSettings.Windowed;pparams.SwapEffect = SwapEffect.Discard;if (deviceSettings.HasHWSupport)	device = new Device(0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, pparams);


Also note that i'm explicitly passing the handle of the form, you will find that in some cases rendering on a panel or other control a problem creating the device will occur if you don't do this, so by default I usually do this.

I hope this helps.
Take care.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.