I am starting to write a DirectX program in C# by following the SDK tutorials. I know this might not be the best way to do this, but it should work none the less. I have started by Creating 2 classes. The first is CMain which just holds my main function:
using System;
using System.Drawing;
using System.Windows.Forms;
using DX = Microsoft.DirectX;
using D3D = Microsoft.DirectX.Direct3D;
namespace Pong
{
public class CMain
{
public CMain()
{
}
[STAThread]
static void Main()
{
CDevice app = new CDevice();
if(!app.InitializeGraphics(true))
{
MessageBox.Show("Could Not Initialize Direct3D Device.\nExiting...");
return;
}
app.ShowDialog();
}
}
}
and the other one is the one to create the device, etc:
using System;
using System.Drawing;
using System.Windows.Forms;
using DX = Microsoft.DirectX;
using D3D = Microsoft.DirectX.Direct3D;
namespace Pong
{
public class CDevice : System.Windows.Forms.Form
{
private D3D.Device m_Device;
private D3D.PresentParameters m_PP;
public CDevice()
{
this.m_Device = null;
this.m_PP = new D3D.PresentParameters();
this.ClientSize = new System.Drawing.Size(800, 600);
this.Name = "frmMain";
this.Text = "Pong: DirectX Accelerated";
}
public bool InitializeGraphics(bool Fullscreen)
{
try
{
this.m_PP.Windowed = !Fullscreen;
this.m_PP.SwapEffect = D3D.SwapEffect.Discard;
this.m_PP.PresentationInterval = D3D.PresentInterval.Immediate;
this.m_Device = new D3D.Device( 0, D3D.DeviceType.Hardware, this, D3D.CreateFlags.SoftwareVertexProcessing, this.m_PP);
return true;
}
catch(DX.DirectXException e)
{
Console.WriteLine("\n+++++++++++\n{0}\nErrorCode: {1}\n+++++++++++", e.ToString(), e.ErrorCode);
return false;
}
}
}
}
This is all the code my application uses, and I thought it should be able to create the device but if fails (throws an exception). I installed the debug runtimes and it tells me the error it throws is Unknown. I even put the error code in the error lookup utility, but again it came up with an error unknown.
Here is what is printed by my Console.Writeline:
+++++++++++
Error in the application.
-2146232832 (Unknown)
at Microsoft.DirectX.Direct3D.Device..ctor(Int32 adapter, DeviceType deviceType, Control renderWindow, CreateFlags behaviorFlags, PresentParameters presentationParameters)
at Pong.CDevice.InitializeGraphics(Boolean Fullscreen) in c:\documents and settings\micahh\my documents\visual studio projects\pong\cdevice.cs:line 31
ErrorCode: -2146232832
+++++++++++
Could someone please tell me what is wrong, and why I can''t get a nice descriptive error from my debugger.
Thanks in advance.