DrawIndexedPrimitives bugged?

Hi everybody!

Does anyone know if DrawIndexedPrimitives is bugged?

I read about people having freezing problems or getting blank screens. I have something completely different: I am trying to draw two triangles with just one shared vertex and the DX function displays just the first triangles!!!

Here is the code for the VertexBuffer:

privatevoid VertexDeclaration()

{

vb =newVertexBuffer(typeof(CustomVertex.PositionColored),5, device,Usage.Dynamic |Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Default);

vertices =newCustomVertex.PositionColored[5];

vertices[0].Position =newVector3(0f, 0f, 0f);

vertices[0].Color =Color.White.ToArgb();

vertices[1].Position =newVector3(5f, 0f, 0f);

vertices[1].Color =Color.White.ToArgb();

vertices[2].Position =newVector3(10f, 0f, 0f);

vertices[2].Color =Color.White.ToArgb();

vertices[3].Position =newVector3(5f, 5f, 0f);

vertices[3].Color =Color.White.ToArgb();

vertices[4].Position =newVector3(10f, 5f, 0f);

vertices[4].Color =Color.White.ToArgb();

vb.SetData(vertices, 0,LockFlags.None);

}

Here is the code for the IndecesDeclaration:

privatevoid IndicesDeclaration()

{

ib =newIndexBuffer(typeof(short), 6, device,Usage.WriteOnly,Pool.Default);

indices =newintDevil;

indices[0] = 3;

indices[1] = 1;

indices[2] = 0;

indices[3] = 4;

indices[4] = 2;

indices[5] = 1;

ib.SetData(indices, 0,LockFlags.None);

}

and this one is the DrawIndexedPrimitives call:

[...]

device.Indices = ib;

device.SetStreamSource(0, vb, 0);

device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 5, 0, 2);

[...]

I also tried to set DeviceType to Reference but nothing has changed...

Any idea?

Thanks!

Gianluca.

[4200 byte] By [GianlucaColucci] at [2007-12-26]
# 1
Try setting the cull mode to none.
WessamBahnassi at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 2

Hello there!

I have already tried by setting Cull to None... nothing changes.

Any other idea?

Thanks!!!

Gian.

GianlucaColucci at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 3
You only need 4 indices for expressing two triangles using the TriStrip primtive type. Plot your triangles on paper and you'll see that the triangles you're drawing are overlapping in a buggy way...
WessamBahnassi at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 4

Hello Wessam,

Thanks for the answer. I will try to implement the same with TriStrip but I still wonder why DrawIndexedPrimitives does not work...

As other people suggested me, at the moment I set device to Reference and not to Hardware, it can not be a hardware related issue, it has to be something in the code... what is wrong then?

Thanks,

Gianluca.

GianlucaColucci at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 5
Gianluca Colucci wrote:
Thanks for the answer. I will try to implement the same with TriStrip but I still wonder why DrawIndexedPrimitives does not work...

I already told you that your triangles make no sense. Your DIP call is using the TriStrip primitive type, and if you look at the SDK docs you can find out what it means:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/d3dprimitivetype.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/triangle_strips.asp
WessamBahnassi at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 6

Hello again.

Ok, I can agree with you, it might have no sense to draw that couple of triangles in that way... but... I found a tutorial on the web... and I am trying to understand how DirectX work by following the several lessons.

I had to stop in one of the first because of this problem. Now, by setting device.Reference, the issue should not be anymore hardware related. So, I really do not understand why it does not work if it does for all the other developers who tried the example.

Is there something wrong with DirectX or with the code?

I contacted also the tutorial author and he has confirmed the program (the one which draw the two triangles by using DrawIndexedPrimitives) should work in any case...

Hope to receive an explanation,

Cheers,

Gianluca.

GianlucaColucci at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 7
Instead of doubting the correctness of some code found on the web, I'd spend the time plotting the triangles on paper and understanding how triangle strips work. Then you can judge for yourself if the code is right or wrong, and see what should be corrected...
WessamBahnassi at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...