كيف ارسم triangle ؟
ما هو الخطأ في الكود الأتي؟؟؟؟؟؟
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
//using Microsoft.DirectX.DirectDraw;
namespace _1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using(Form1 frm=new Form1())
{
frm.Show();
frm.InitializeGraphics();
Application.Run(frm);
}
}
private Device device=null;
//we will initialze our graphics device here
public void InitializeGraphics()
{
PresentParameters presentparams=new PresentParameters();
presentparams.Windowed=true;
presentparams.SwapEffect=SwapEffect.Discard;
device=new Device(0,DeviceType.Hardware,this,CreateFlags.SoftwareVertexProcessing,presentparams);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target,Color.DarkOrange,1.0f,0);
device.Present();
CustomVertex.TransformedColored[] verts=new Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored[3];
verts[0].SetPosition(new Vector4(this.Width/2.0f,5.0f,0.5f,1.0f));
verts[0].Color=Color.Black.ToArgb();
verts[1].SetPosition(new Vector4(this.Width-(this.Width/5.0f),this.Height-(this.Height/5.0f),0.5f,1.0f));
verts[1].Color=Color.Black.ToArgb();
verts[2].SetPosition(new Vector4(this.Width/5.0f,this.Height-(this.Height/5.0f),0.5f,1.0f));
verts[2].Color=Color.Black.ToArgb();
device.BeginScene();
device.VertexFormat=CustomVertex.TransformedColored.Format;
device.DrawUserPrimitives(PrimitiveType.TriangleList,1,verts);
device.EndScene();
// this.Invalidate();
// this.SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.Opaque,true);
}
private void button1_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}