, Visual C#

       


44.1. .

using (Form1 myForm1 = new Form1())

{

if (!myForm1.InitializeDirectX())

{

MessageBox.Show(" DirectX.");

return;

}

// Form1:

myForm1.Show();

// Form1:

while (myForm1.Created)

{



myForm1.myRendering();

Application.DoEvents();

}

}

Form1 Cancel . Form1.cs , (Close()).

Form2 ( Help Form1) . Form1.cs , :

Form2 myForm2 = new Form2(); myForm2.Show(); (44.1)

Project Add Windows Form, Add New Item Templates Windows Form, Name Form2 Add ( Open VS). Form2, ( ) . ( ) Next>> ( <<Back) (44.1) .

Form1.cs (, ) Form1 Direct3D.

44.2. .

//

// myDevice Device:

Device myDevice = null;

// Direct3D:

public bool InitializeDirectX()

{

try

{

PresentParameters myPresentParameters =

new PresentParameters();

myPresentParameters.Windowed = true;

myPresentParameters.SwapEffect = SwapEffect.Discard;

myDevice = new Device(0, DeviceType.Hardware,


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);
}
// :


this, CreateFlags.SoftwareVertexProcessing,
myPresentParameters);
return true;
}
catch (DirectXException)
{
return false;
}
}
// :
public void myRendering()
{
if (myDevice == null)
return;
// - Form1:
myDevice.Clear(ClearFlags.Target,
System.Drawing.Color.White, 1.0f, 0);
// :
myDevice.BeginScene();
// :
myDevice.EndScene();
myDevice.Present();
}
// Form1 Esc:
protected override void OnKeyPress(
System.Windows.Forms.KeyPressEventArgs e)
{
if ((int)(byte)e.KeyChar ==
(int)System.Windows.Forms.Keys.Escape)
this.Close();
}
44.3. .
// :
Device myDevice = null;
VertexBuffer myVertexBuffer = null;
// Direct3D:
public bool InitializeDirectX()
{
try
{
PresentParameters myPresentParameters =
new PresentParameters();
myPresentParameters.Windowed = true;
myPresentParameters.SwapEffect = SwapEffect.Discard;
myDevice = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing,
myPresentParameters);
this.OnCreateDevice(myDevice, null);
return true;
}
catch (DirectXException)
{
return false;
}
}
// :
public void OnCreateDevice(object sender, EventArgs e)
{
// 3-x :
myVertexBuffer = new VertexBuffer(
typeof(CustomVertex.TransformedColored), 3,
myDevice, 0, CustomVertex.TransformedColored.Format,
Pool.Default);
myVertexBuffer.Created += new System.EventHandler(
this.OnCreateVertexBuffer);


this.OnCreateVertexBuffer(myVertexBuffer, null);
}
// :
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
GraphicsStream myGraphicsStream = myVertexBuffer.Lock(0, 0, 0);
CustomVertex.TransformedColored[] Vertex =
new CustomVertex.TransformedColored[3];
// 0:
Vertex[0].X = 150; Vertex[0].Y = 50; Vertex[0].Z = 0.5f;
Vertex[0].Rhw = 1;
Vertex[0].Color = System.Drawing.Color.Aqua.ToArgb();
// 1:
Vertex[1].X = 250; Vertex[1].Y = 300; Vertex[1].Z = 0.5f;
Vertex[1].Rhw = 1;
Vertex[1].Color = System.Drawing.Color.Black.ToArgb();
// 2:
Vertex[2].X = 50; Vertex[2].Y = 300; Vertex[2].Z = 0.5f;
Vertex[2].Rhw = 1;
Vertex[2].Color = System.Drawing.Color.LightPink.ToArgb();
myGraphicsStream.Write(Vertex);
myVertexBuffer.Unlock();
}
//
// :
public void myRendering()
{
if (myDevice == null)
return;
// (Color.White) Form1:
myDevice.Clear(ClearFlags.Target,
System.Drawing.Color.White, 1.0f, 0);
// :
myDevice.BeginScene();
myDevice.SetStreamSource(0, myVertexBuffer, 0);
myDevice.VertexFormat = CustomVertex.TransformedColored.Format;
myDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
// :
myDevice.EndScene();
myDevice.Present();
}
Form1.cs ( Program.cs) Main, ( Form1 ).
44.4. .
using (Form1 myForm1 = new Form1())
{
if (!myForm1.InitializeDirectX())
{
MessageBox.Show(" DirectX.");
return;
}
// Form1:


myForm1.Show();
// Form1:
while (myForm1.Created)
{
myForm1.myRendering();
Application.DoEvents();
}
}
44.5. .
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest,
int nXDest, int nYDest, int nWidth, int nHeight,
IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap myMemoryImage;
private void myCaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
myMemoryImage = new Bitmap(s.Width, s.Height,
myGraphics);
Graphics myMemoryGraphics =
Graphics.FromImage(myMemoryImage);
IntPtr dc0 = myGraphics.GetHdc();
IntPtr dc1 = myMemoryGraphics.GetHdc();
BitBlt(dc1, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height,
dc0, 0, 0, 13369376);
myGraphics.ReleaseHdc(dc0);
myMemoryGraphics.ReleaseHdc(dc1);
}
PrintDocument PrintDialog, PrintDocument. Form1.cs , ( ) .
44.6. .
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(myMemoryImage, 0, 0);
}
Print (. 44.7) . Form1.cs , .
44.7. .
private void button1_Click(object sender, EventArgs e)


{
// :
myCaptureScreen();
// printDialog1
//printDocument1 Document:
printDialog1.Document = printDocument1;
// Print
//ShowDialog()
// OK Print
// Print():
if (printDialog1.ShowDialog() == DialogResult.OK)
printDocument1.Print();
}
( , ) :
System.Windows.Forms.DialogResult result =
printDialog1.ShowDialog();
if (result == DialogResult.OK)
printDocument1.Print();
Form1.cs (, : File, Open, File) (namespace Visual_DirectX_n3) :
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
Form1 (. 44.8), Esc . Form1.cs (, ) .
44.8. .
// .
// :
Device myDevice = null;
// :
VertexBuffer myVertexBuffer1 = null;
// :
VertexBuffer myVertexBuffer2 = null;
// Direct3D:
public bool InitializeDirectX()
{
try
{
// :
PresentParameters myPresentParameters1 =
new PresentParameters();


myPresentParameters1.Windowed = true;
myPresentParameters1.SwapEffect = SwapEffect.Discard;
myDevice = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing,
myPresentParameters1);
this.OnCreateDevice(myDevice, null);
// :
PresentParameters myPresentParameters2 =
new PresentParameters();
myPresentParameters2.Windowed = true;
myPresentParameters2.SwapEffect = SwapEffect.Discard;
myDevice = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing,
myPresentParameters2);
this.OnCreateDevice(myDevice, null);
return true;
}
catch (DirectXException)
{
return false;
}
}
//
// :
public void myRendering()
{
if (myDevice == null)
return;
myDevice.Clear(ClearFlags.Target,
System.Drawing.Color.White, 1.0f, 0);
myDevice.VertexFormat =
CustomVertex.TransformedColored.Format;
// :
myDevice.BeginScene();
// :
myDevice.SetStreamSource(0, myVertexBuffer1, 0);
myDevice.DrawPrimitives(PrimitiveType.TriangleList,0, 1);
// :
myDevice.SetStreamSource(0, myVertexBuffer2, 0);
myDevice.DrawPrimitives(PrimitiveType.TriangleStrip,0,2);
// :
myDevice.EndScene();
myDevice.Present();
}
// :
public void OnCreateDevice(object sender, EventArgs e)
{
Device myDev = (Device)sender;
// :
myVertexBuffer1 = new VertexBuffer(
typeof(CustomVertex.TransformedColored), 3,
myDev, 0, CustomVertex.TransformedColored.Format,
Pool.Default);
myVertexBuffer1.Created +=
new System.EventHandler(this.OnCreateVertexBuffer1);


this.OnCreateVertexBuffer1(myVertexBuffer1, null);
// :
myVertexBuffer2 = new VertexBuffer(
typeof(CustomVertex.TransformedColored), 4,
myDev, 0, CustomVertex.TransformedColored.Format,
Pool.Default);
myVertexBuffer2.Created += new System.EventHandler(
this.OnCreateVertexBuffer2);
this.OnCreateVertexBuffer2(myVertexBuffer2, null);
}
// :
public void OnCreateVertexBuffer1(object sender, EventArgs e)
{
VertexBuffer myVB1 = (VertexBuffer)sender;
GraphicsStream myGraphicsStream1 = myVB1.Lock(0, 0, 0);
CustomVertex.TransformedColored[] Vertex1 =
new CustomVertex.TransformedColored[3];
// 0:
Vertex1[0].X = 150; Vertex1[0].Y = 50; Vertex1[0].Z=0.5f;
Vertex1[0].Rhw = 1;
Vertex1[0].Color = System.Drawing.Color.Aqua.ToArgb();
// 1:
Vertex1[1].X = 250; Vertex1[1].Y =300; Vertex1[1].Z=0.5f;
Vertex1[1].Rhw = 1;
Vertex1[1].Color = System.Drawing.Color.Black.ToArgb();
// 2:
Vertex1[2].X = 50; Vertex1[2].Y = 300; Vertex1[2].Z=0.5f;
Vertex1[2].Rhw = 1;
Vertex1[2].Color =
System.Drawing.Color.LightPink.ToArgb();
myGraphicsStream1.Write(Vertex1);
myVB1.Unlock();
}
// :
public void OnCreateVertexBuffer2(object sender, EventArgs EvArgs)
{
VertexBuffer myVB2 = (VertexBuffer)sender;
GraphicsStream myGraphicsStream2 = myVB2.Lock(0, 0, 0);
CustomVertex.TransformedColored[] Vertex2 =
new CustomVertex.TransformedColored[4];
// 0:
Vertex2[0].X = 300.0f; Vertex2[0].Y = 300.0f;
Vertex2[0].Z = 0.5f; Vertex2[0].Rhw = 1;
Vertex2[0].Color = System.Drawing.Color.Black.ToArgb();
// 1:
Vertex2[1].X = 300.0f; Vertex2[1].Y = 50.0f;
Vertex2[1].Z = 0.5f; Vertex2[1].Rhw = 1;
Vertex2[1].Color = System.Drawing.Color.White.ToArgb();


// 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)


{
Device myDev = (Device)sender;
// CullMode,
// :
myDev.RenderState.CullMode = Cull.None;
// Direct3D,
// :
myDev.RenderState.Lighting = false;
}
// :
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
// 4- :
VertexBuffer myVB = (VertexBuffer)sender;
CustomVertex.PositionColored[] Vertex = (
CustomVertex.PositionColored[])myVB.Lock(0, 0);
// 0:
Vertex[0].X = -1.0f; Vertex[0].Y = -1.0f;
Vertex[0].Z = 0.0f;
Vertex[0].Color = System.Drawing.Color.Black.ToArgb();
// 1:
Vertex[1].X = -1.0f; Vertex[1].Y = 1.0f;
Vertex[1].Z = 0.0f;
Vertex[1].Color =
System.Drawing.Color.MediumOrchid.ToArgb();
// 2:
Vertex[2].X = 1.0f; Vertex[2].Y = -1.0f;
Vertex[2].Z = 0.0f;
Vertex[2].Color = System.Drawing.Color.Black.ToArgb();
// 3:
Vertex[3].X = 1.0f; Vertex[3].Y = 1.0f;
Vertex[3].Z = 0.0f;
Vertex[3].Color = System.Drawing.Color.Cornsilk.ToArgb();
myVB.Unlock();
}
// :
public void myRendering()
{
if (myDevice == null) return;
if (myPause) return;
// Form1 :
myDevice.Clear(ClearFlags.Target,
System.Drawing.Color.White, 1.0f, 0);
// :
myDevice.BeginScene();
// :
SetupMatrices();
myDevice.SetStreamSource(0, myVertexBuffer, 0);
myDevice.VertexFormat =
CustomVertex.PositionColored.Format;
// :
myDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
// :
myDevice.EndScene();
myDevice.Present();
}
// :


private void SetupMatrices()
{
// Matrix,
// y.
// 2*PI
// 1000 (1 ):
int iTime = Environment.TickCount % 1000;
float fAngle = iTime * (2.0f * (float)Math.PI) / 1000.0f;
myDevice.Transform.World = Matrix.RotationY(fAngle);
//
// (view matrix):
myDevice.Transform.View = Matrix.LookAtLH(
new Vector3(0.0f, 3.0f, -5.0f),
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f));
// (projection matrix)
// :
myDevice.Transform.Projection = Matrix.PerspectiveFovLH(
(float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
}
//
// Form1:
protected override void OnResize(System.EventArgs e)
{
myPause = ((this.WindowState ==
FormWindowState.Minimized) || !this.Visible);
}
Form1.cs ( Program.cs) Main, ( Form1 ).


public void OnResetDevice(object sender, EventArgs e)
{
Device myDev = (Device)sender;
// CullMode,
// :
myDevice.RenderState.CullMode = Cull.None;
// Z - :
myDevice.RenderState.ZBufferEnable = true;
// :
myDevice.RenderState.Lighting = true;
}
// :
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
VertexBuffer myVB = (VertexBuffer)sender;
// PositionNormal
// 100 :
CustomVertex.PositionNormal[] Vertex =
(CustomVertex.PositionNormal[])myVB.Lock(0, 0);
for (int i = 0; i < 50; i++)
{
// :
float theta = (float)(2 * Math.PI * i) / 49;
// .
// :
Vertex[2 * i].Position =
new Vector3((float)Math.Sin(theta), -1,
(float)Math.Cos(theta));
// :
Vertex[2 * i + 1].Normal =
new Vector3((float)Math.Sin(theta), -1,
(float)Math.Cos(theta));
}
// :
myVB.Unlock();
}
// :
private void SetupMatrices()
{
// (world matrix),
// y:
myDevice.Transform.World = Matrix.RotationAxis(
new Vector3(
(float)Math.Cos(Environment.TickCount / 250.0f), 1,
(float)Math.Sin(Environment.TickCount / 250.0f)),
Environment.TickCount / 3000.0f);
//
// (view matrix):
myDevice.Transform.View = Matrix.LookAtLH(
new Vector3(0.0f, 3.0f, -5.0f),
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f));


// (projection matrix)
// :
myDevice.Transform.Projection =
Matrix.PerspectiveFovLH(
(float)Math.PI / 4.0f, 1.0f, 1.0f, 100.0f);
}
// ARGB:
private void SetupLights()
{
// .
// :
Material myMaterial = new Material();
Color myColor = Color.White;
myMaterial.Diffuse = myColor;
myMaterial.Ambient = myColor;
myDevice.Material = myMaterial;
//
// :
myDevice.Lights[0].Type = LightType.Directional;
myDevice.Lights[0].Diffuse = Color.DarkTurquoise;
myDevice.Lights[0].Direction = new Vector3(
(float)Math.Cos(Environment.TickCount / 250.0f), 1.0f,
(float)Math.Sin(Environment.TickCount / 250.0f));
// :
myDevice.Lights[0].Enabled = true;
// (Ambient)
// :
myDevice.RenderState.Ambient = Color.FromArgb(0x202020);
}
// :
public void myRendering()
{
if (myPause) return;
// Form1 :
myDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
Color.White, 1.0f, 0);
// :
myDevice.BeginScene();
// :
SetupLights();
// (world, view, projection):
SetupMatrices();
myDevice.SetStreamSource(0, myVertexBuffer, 0);
myDevice.VertexFormat =
CustomVertex.PositionNormal.Format;
// :
myDevice.DrawPrimitives(
PrimitiveType.TriangleStrip, 0, (4 * 25) - 2);
// :
myDevice.EndScene();
// :
myDevice.Present();
}
//
// Form1:


protected override void OnResize(System.EventArgs e)
{
myPause = ((this.WindowState ==
FormWindowState.Minimized) || !this.Visible);
}
// Form1 Esc:
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ((int)(byte)e.KeyChar == (int)Keys.Escape)
this.Close();
}
45.2. .
using (Form1 myForm1 = new Form1())
{
if (!myForm1.InitializeDirectX())
{
MessageBox.Show(" DirectX.");
return;
}
// Form1:
myForm1.Show();
// Form1:
while (myForm1.Created)
{
myForm1.myRendering();
Application.DoEvents();
}
}
Form1.cs (, : File, Open, File) (namespace Visual_DirectX_n6) :
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
Form1 (. 45.4) .
Form1.cs (, ) ( ) .
45.3. .
// .
// :
Device myDevice = null;
VertexBuffer myVertexBuffer = null;
// myTexture
// Texture:
Texture myTexture = 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.PositionNormalTextured), 100,
myDev, Usage.WriteOnly,
CustomVertex.PositionNormalTextured.Format,
Pool.Default);
myVertexBuffer.Created +=
new System.EventHandler(this.OnCreateVertexBuffer);
this.OnCreateVertexBuffer(myVertexBuffer, null);
}
// :
public void OnResetDevice(object sender, EventArgs e)
{
Device myDev = (Device)sender;
// CullMode,
// :
myDev.RenderState.CullMode = Cull.None;
// :
myDev.RenderState.Lighting = false;
// Z - (ZBuffer):
myDev.RenderState.ZBufferEnable = true;
// .
// Texture_1
// :
myTexture = TextureLoader.FromFile(myDev,
Application.StartupPath + @"\..\..\Texture_1.bmp");
}
// :
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
VertexBuffer myVB = (VertexBuffer)sender;
// PositionNormalTextured


// 100 :
CustomVertex.PositionNormalTextured[] Vertex =
(CustomVertex.PositionNormalTextured[])myVB.Lock(0, 0); // Lock the buffer (which will return our structs)
for (int i = 0; i < 50; i++)
{
// :
float theta = (float)(2 * Math.PI * i) / 49;
// :
Vertex[2 * i].Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta));
// v- :
Vertex[2 * i].Tv = 1.0f;
// :
Vertex[2 * i + 1].Position = new Vector3((float)Math.Sin(theta), 1, (float)Math.Cos(theta));
// u- :
Vertex[2 * i + 1].Tu = ((float)i) / (50 - 1);
}
// :
myVB.Unlock();
}
// :
private void SetupMatrices()
{
// (world matrix),
// y.
myDevice.Transform.World = Matrix.RotationAxis(
new Vector3(
(float)Math.Cos(Environment.TickCount / 250.0f), 1,
(float)Math.Sin(Environment.TickCount / 250.0f)),
Environment.TickCount / 1000.0f);
//
// (view matrix):
myDevice.Transform.View = Matrix.LookAtLH(
new Vector3(0.0f, 3.0f, -5.0f),
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f));
// (projection matrix)
// :
myDevice.Transform.Projection =
Matrix.PerspectiveFovLH(
(float)Math.PI / 4.0f, 1.0f, 1.0f, 100.0f);
}
// :
public void myRendering()
{
if (myPause) return;
// Form1 :
myDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer,


Color.White, 1.0f, 0);
// :
myDevice.BeginScene();
// (world, view, projection):
SetupMatrices();
// :
myDevice.SetTexture(0, myTexture);
myDevice.TextureState[0].ColorOperation =
TextureOperation.Modulate;
myDevice.TextureState[0].ColorArgument1 =
TextureArgument.TextureColor;
myDevice.TextureState[0].ColorArgument2 =
TextureArgument.Diffuse;
myDevice.TextureState[0].AlphaOperation =
TextureOperation.Disable;
// :
myDevice.SetStreamSource(0, myVertexBuffer, 0);
myDevice.VertexFormat =
CustomVertex.PositionNormalTextured.Format;
myDevice.DrawPrimitives(
PrimitiveType.TriangleStrip, 0, (4 * 25) - 2);
// :
myDevice.EndScene();
// :
myDevice.Present();
}
//
// Form1:
protected override void OnResize(System.EventArgs e)
{
myPause = ((this.WindowState ==
FormWindowState.Minimized) || !this.Visible);
}
// Form1 Esc:
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ((int)(byte)e.KeyChar == (int)Keys.Escape)
this.Close();
}
Form1.cs ( Program.cs) Main, .
45.4. .
using (Form1 myForm1 = new Form1())
{
if (!myForm1.InitializeDirectX())
{
MessageBox.Show(" DirectX.");
return;
}
// Form1:
myForm1.Show();
// Form1:
while (myForm1.Created)
{
myForm1.myRendering();
Application.DoEvents();
}
}
Visual C# DirectX .