, Visual C#



Form1.cs (, : File, Open, File) (namespace Visual_DirectX_n5) :

using Microsoft.DirectX;

using Microsoft.DirectX.Direct3D;

using Direct3D = Microsoft.DirectX.Direct3D;

45.1. .

// .

// :

Device myDevice = null;

VertexBuffer myVertexBuffer = null;

PresentParameters myPresentParameters =

new PresentParameters();

bool myPause = false;

// DirectX:

public bool InitializeDirectX()

{

try

{

myPresentParameters.Windowed = true;

myPresentParameters.SwapEffect =

SwapEffect.Discard;

myPresentParameters.EnableAutoDepthStencil = true;

myPresentParameters.AutoDepthStencilFormat =

DepthFormat.D16;

// :

myDevice = new Device(0, DeviceType.Hardware, this,

CreateFlags.SoftwareVertexProcessing,

myPresentParameters);

myDevice.DeviceReset +=

new System.EventHandler(this.OnResetDevice);

this.OnCreateDevice(myDevice, null);

this.OnResetDevice(myDevice, null);

myPause = false;

return true;

}

catch (DirectXException)

{

// DirectX:

return false;

}

}

// :

public void OnCreateDevice(object sender, EventArgs e)

{

Device myDev = (Device)sender;

myVertexBuffer = new VertexBuffer(

typeof(CustomVertex.PositionNormal), 100, myDev,

Usage.WriteOnly, CustomVertex.PositionNormal.Format,

Pool.Default);

myVertexBuffer.Created += new System.EventHandler(

this.OnCreateVertexBuffer);

this.OnCreateVertexBuffer(myVertexBuffer, null);

}

// :