, Visual C#


- 8


 

// 2:

Vertex2[2].X = 500.0f; Vertex2[2].Y = 300.0f;

Vertex2[2].Z = 0.5f; Vertex2[2].Rhw = 1;

Vertex2[2].Color = System.Drawing.Color.Blue.ToArgb();

 

// 3:

Vertex2[3].X = 500.0f; Vertex2[3].Y = 50.0f;

Vertex2[3].Z = 0.5f; Vertex2[3].Rhw = 1;

Vertex2[3].Color = System.Drawing.Color.Green.ToArgb();

myGraphicsStream2.Write(Vertex2);

myVB2.Unlock();

}

44.9. .

// :

Device myDevice = null; // Our rendering device

VertexBuffer myVertexBuffer = null;

PresentParameters myPresentParameters =

new PresentParameters();

bool myPause = false;

 

// DirectX:

public bool InitializeDirectX()

{

try

{

myPresentParameters.Windowed = true;

myPresentParameters.SwapEffect = SwapEffect.Discard;

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)

{

return false;

}

}

 

// :

public void OnCreateDevice(object sender, EventArgs e)

{

Device myDev = (Device)sender;

// 4 :

myVertexBuffer = new VertexBuffer(

typeof(CustomVertex.PositionColored), 4, myDev, 0,

CustomVertex.PositionColored.Format, Pool.Default);

// - Created:

myVertexBuffer.Created += new System.EventHandler(

this.OnCreateVertexBuffer);

this.OnCreateVertexBuffer(myVertexBuffer, null);

}

// Direct3D:

public void OnResetDevice(object sender, EventArgs e)