DirectX C# : La référence d'objet n'est pas définie à une instance d'un objet.
Bonjour, lorsque je lance un tout petit programme c# utilisant directX, je vois la winform s'afficher une seconde puis j'ai :
http://img58.imageshack.us/img58/8605/sanstitrewu9.png
Voici mon code c# :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectX
{
public partial class Form1 : Form
{
private Device device = null;
public Form1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(this.Render);
}
public void InitializeGraphics()
{
// Définition des PresentParameters
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
// Creation de notre device
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
device.DeviceReset += new EventHandler(OnResetDevice);
device.DeviceLost += new EventHandler(OnLostDevice);
device.Disposing += new EventHandler(OnDisposingDevice);
}
private void OnResetDevice(object sender, EventArgs e)
{
if (device == null || device.Disposed) { return; }
}
private bool isDeviceLost = false;
private void OnLostDevice(object sender, EventArgs e)
{
isDeviceLost = true;
}
private bool isTerminated = false;
private void OnDisposingDevice(object sender, EventArgs e)
{
isTerminated = true;
device = null;
}
private void Render(object sender, PaintEventArgs e)
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0, 1.0f, 0);
device.BeginScene();
device.EndScene();
device.Present();
}
public void Clear(ClearFlags flags, Color color, float zdepth, int stencil) { }
}
} |
Quelqu'un sait de quoi il s'agit ?
Merci,