Reputation: 21
I'm trying to create a window and initializing a device to the window but every time I run the program the window does not load. I am doing this in visual studio 2015 for a windows forms application. here the form1.cs:
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
namespace DirectXTutorial2
{
public partial class Form1 : Form
{
private Device device;
public Form1()
{
InitializeComponent();
InitializeDevice();
}
public void InitializeDevice()
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
}
private void Render()
{
device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 0, 1);
device.Present();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Does anyone know of a solution to this? I don't know if it helps but I am running windows 10, 64 bit, Directx 2010, and I have been added my references before.
Upvotes: 0
Views: 1148
Reputation: 21
okay, i have found a solution to my problem. DirectX for managed code is no longer supported by the devs. the latest framework that works for DirectX is .net Framework 3.5. managed code also does not support 64 bit. to fix this problem go to project properties. in the application tab find target framework and change your .net framework to 3.5 or less. next go to the build tab and find platform target, change this to x86.
Upvotes: 2
Reputation: 490
First think use try catch in your application, because there is alot of stuff happening in DirectX, so you need to confirm the step, where you are getting error.
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed=true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
}
catch (DirectXException)
{
return false;
}
Try to use different device type like DeviceType.Software
.
After clearing your device add begin and end scene
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
device.BeginScene();
device.EndScene();
device.Present();
And try calling your 'Render; function in 'Main' function
Upvotes: 0