DirectX9 Initialize Problem
Hello Community,
I just started with DirectX Development and instantly encountered a problem. While initializing the program just stops running (without throwing an exception) and hence won't show at all. Here is the code:
public class MainForm : Form
{
private Device device;
private System.ComponentModel.Container components = null;
public MainForm()
{
InitializeComponent();
}
#region Windows
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(500, 500);
this.Text = "DirectX_Test";
}
#endregion
public bool InitializeGraphics()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target, Color.DarkSlateBlue , 1.0f, 0);
device.Present();
}
#region StaticMain
[STAThread]
private static void Main(string[] args)
{
using (MainForm frm = new MainForm())
{
if(!frm.InitializeGraphics()) // Problem here <----
{
MessageBox.Show("Could not initialize Direct3D. This tutorial will exit.");
return;
}
frm.Show();
}
}
#endregion
}
Now, when I tried to debug right at frm.InitializeGraphics(). It won't even enter the method it just does nothing. When I remove the code inside that method it will show so I figured there must be a problem with the DirectX.
I run the DirectX9 SDK June '10.
Any ideas or help?
Thank you.