i try to draw a polygon which have 6 points .But no matter I
draw it,It always cann't be draw correctly.
My main code is below:
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
VertexBuffer vb = (VertexBuffer)sender;
GraphicsStream stm = vb.Lock(0, 0, 0);
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored
;
verts[0].X=150;verts[0].Y=50;verts[0].Z=0.5f; verts[0].Rhw=1; verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
verts[1].X=180;verts[1].Y=90;verts[1].Z=0.5f; verts[1].Rhw=1; verts[1].Color = System.Drawing.Color.Brown.ToArgb();
verts[2].X=350;verts[2].Y=150;verts[2].Z=0.5f; verts[2].Rhw=1; verts[2].Color = System.Drawing.Color.Orange.ToArgb();
verts[3].X=250;verts[3].Y=250;verts[3].Z=0.5f; verts[3].Rhw=1; verts[3].Color = System.Drawing.Color.LightPink.ToArgb();
verts[4].X=50;verts[4].Y=250;verts[4].Z=0.5f; verts[4].Rhw=1; verts[4].Color = System.Drawing.Color.LightPink.ToArgb();
verts[5].X=25;verts[5].Y=150;verts[5].Z=0.5f; verts[5].Rhw=1; verts[5].Color = System.Drawing.Color.Blue.ToArgb();
stm.Write(verts);
vb.Unlock();
private void Render()
{
device.Clear(ClearFlags.Target, System.Drawing.Color.Yellow, 1.0f, 0);
device.BeginScene();
device.SetStreamSource( 0, vertexBuffer, 0);
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawPrimitives(PrimitiveType.TriangleFan,0,4); // method1
device.DrawPrimitives(PrimitiveType.TriangleList,0,4);//method2
device.DrawPrimitives(PrimitiveType.TriangleStrip,0,4);//method3
device.EndScene();
device.Present();
}
}
No matter I use any DrawPrimitives method.It always cann't draw correctly.
please anybody teach me how to do.
But I don't want to detect and sort points array before drawing a polygon .

why cann't the 2D polygon be drawed correctly?
reukiodo
DirectX can only draw triangles. So for a 6 pointed polygon you need to have more than 6 vertices.
If the polygon is an arbitrary shape and can be convex or concave then you have to find an algorithm to break it up into triangles.
If your polygon is something you know all the points of then you need to triangulate it yourself and decide if you want to use triangles (where you give 3 vertices for each triangle), strips (where the 1st triangel gets 3 points and the remainder use the last 2 and 1 new one) or fans (st triangel gets 3 points and the remainder use the 1st point and the last point as well as a new one). see http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node17.html and
http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node18.html (yes they are open GL but the diagrams explain it).
If thats not the problem then some screen shots would help debug. People generally don't have time to debug and run your code.
ShiroAmada
Anyway, please specify what is not being drawed correctly.
What is being drawed, and what should be being drawed