| Poster | : phoenix_07p | | Posts | : 1 | | Country | : India | | City | : Pune |
| | | | Posted by phoenix_07p on 07/08/2008 at 15:08:43
| | namespace DXApp1
{
public class Program:System.Windows.Forms.Form
{
Device device;
//CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3];
CustomVertex.PositionColored[] vertices;
VertexBuffer vb;
IndexBuffer ib;
static int row=5, column=2;
Program()
{
this.ClientSize = new Size(500, 500);
this.Text = "DX Application";
}
public void SetCamera()
{
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1f, 50f);
device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, -30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
device.RenderState.Lighting = false;
device.RenderState.FillMode = FillMode.WireFrame;
device.RenderState.CullMode = Cull.None;
}
public void InitializeVertexBuffer()
{
vb = new VertexBuffer(typeof(CustomVertex.PositionColored), 10, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
vertices = new CustomVertex.PositionColored[10];
vertices[0].Position = new Vector3(0f, 0f, 0f);
vertices[0].Color = Color.White.ToArgb();
vertices[1].Position = new Vector3(5f, 0f, 0f);
vertices[1].Color = Color.White.ToArgb();
vertices[2].Position = new Vector3(10f, 0f, 0f);
vertices[2].Color = Color.White.ToArgb();
vertices[3].Position = new Vector3(15f, 0f, 0f);
vertices[3].Color = Color.White.ToArgb();
vertices[4].Position = new Vector3(20f, 0f, 0f);
vertices[4].Color = Color.White.ToArgb();
vertices[5].Position = new Vector3(5f, 0f, 0f);
vertices[5].Color = Color.White.ToArgb();
vertices[6].Position = new Vector3(5f, 5f, 0f);
vertices[6].Color = Color.White.ToArgb();
vertices[7].Position = new Vector3(5f, 10f, 0f);
vertices[7].Color = Color.White.ToArgb();
vertices[8].Position = new Vector3(5f, 15f, 0f);
vertices[8].Color = Color.White.ToArgb();
vertices[9].Position = new Vector3(5f, 20f, 0f);
vertices[9].Color = Color.White.ToArgb();
vb.SetData(vertices, 0, LockFlags.None);
}
public bool InitializeGraphics()
{
try
{
PresentParameters presentParams = new PresentParameters();
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.Windowed = true;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
return true;
}
catch (DirectXException)
{
return false;
}
}
protected override void OnPaint(PaintEventArgs e)
{
this.Render();
}
public void Render()
{
device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);
device.BeginScene();
device.VertexFormat = CustomVertex.PositionColored.Format;
device.SetStreamSource(0, vb, 0);
device.DrawPrimitives(PrimitiveType.TriangleStrip, 0,8);
device.EndScene();
device.Present();
}
static void Main()
{
using (Program instance = new Program())
{
if (!instance.InitializeGraphics())
{
MessageBox.Show("DX Error");
}
instance.Show();
instance.SetCamera();
instance.InitializeVertexBuffer();
while (instance.Created)
{
instance.Render();
Application.DoEvents();
}
}
}
}
}
This is my code......
It wasn't working. There are no errors.Screen clears just fine. but nothin else shows up.I don't exactly want to draw the triangle. But when i passed the same vertices to ur code atleast something showed up.I modified ur code a little bit. Plz tell me why my code won't work. all that the modified code was this....
private void VertexDeclaration()
{
vb = new VertexBuffer(typeof(CustomVertex.PositionColored), 10, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
vertices = new CustomVertex.PositionColored[10];
vertices[0].Position = new Vector3(0f, 0f, 0f);
vertices[0].Color = Color.White.ToArgb();
vertices[1].Position = new Vector3(5f, 0f, 0f);
vertices[1].Color = Color.White.ToArgb();
vertices[2].Position = new Vector3(10f, 0f, 0f);
vertices[2].Color = Color.White.ToArgb();
vertices[3].Position = new Vector3(15f, 0f, 0f);
vertices[3].Color = Color.White.ToArgb();
vertices[4].Position = new Vector3(20f, 0f, 0f);
vertices[4].Color = Color.White.ToArgb();
vertices[5].Position = new Vector3(5f, 0f, 0f);
vertices[5].Color = Color.White.ToArgb();
vertices[6].Position = new Vector3(5f, 5f, 0f);
vertices[6].Color = Color.White.ToArgb();
vertices[7].Position = new Vector3(5f, 10f, 0f);
vertices[7].Color = Color.White.ToArgb();
vertices[8].Position = new Vector3(5f, 15f, 0f);
vertices[8].Color = Color.White.ToArgb();
vertices[9].Position = new Vector3(5f, 20f, 0f);
vertices[9].Color = Color.White.ToArgb();
vb.SetData(vertices, 0, LockFlags.None);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);
device.BeginScene();
device.VertexFormat = CustomVertex.PositionColored.Format;
device.SetStreamSource(0, vb, 0);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 8);
device.EndScene();
device.Present();
this.Invalidate();
angle += 0.05f;
}
I removed the indices declaration completely.
I don't really care whether triangles show up correctly just that something shows up. I am tired of trying.
My question is just that why nothin shows up in my code when there is some output from ur code.
Thanx. | |
|
|