iljanated

Hi,
the code below shows how I fill an indexbuffer with the value 0 for each index. When I draw the primitive, I should see 1 point (with coordinates of the first vertex in my vertexbuffer) or nothing at all (since I'm drawing a line).
However, my program draws the first 10 vertices in the vertexbuffer ... it's like it ignores the indexbuffer. Also when I come closer the lines disapear.
(The indexbuffer is created after effect.begin.)

VertexBuffer vertexBuffer = new VertexBuffer(graphicsDevice,typeof(VertexPositionNormalTexture),vertexList.Length, ResourceUsage.None, ResourceManagementMode.Automatic);

// (vertexlist is an array with vertices of type VertexPositionNormalTexture)

FanIndexArray = new Int32[10];
for (int i = 0; i < FanIndexArray.Length; i++)
{
FanIndexArrayIdea = 0;
}
FanIndexBuffer = new IndexBuffer(
GraphicsDevice,
typeof(Int32),
10,
ResourceUsage.None,
ResourceManagementMode.Automatic);

FanIndexBuffer.SetData<Int32>(FanIndexArray);
GraphicsDevice.Indices = FanIndexBuffer;
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList,0,0,10,0,10);




Re: XNA Framework indexbuffer is ignored

Kyle_W

I don't understand why you would use an index buffer with all indices set to zero. If you just want to draw a single point, use a point list instead of a line list. I would guess that the lines disappear when you get close to them because they cross the near clipping plane boundary. I assume you have seen this, but here is a link to the docs for XNA point list and line list primitives:

http://msdn2.microsoft.com/en-us/library/bb196414.aspx





Re: XNA Framework indexbuffer is ignored

Shawn Hargreaves - MSFT

Have you tried running with the debug DirectX runtime and checking the native debug output

Also, looking at a capture of this program in PIX might help.

Failing that, please post a complete program that we can compile and run: just that snippet doesn't look like enough to spot what you're doing wrong.





Re: XNA Framework indexbuffer is ignored

iljanated

I'll try the PIX first.

The reason I set the whole buffer to zero is that my real program is an implementation of the SOAR terrain algorithm (using fans instead of trianglestrips). It worked with NonIndexed DrawPrimitives calls. But since I changed it for an indexed implementation , nothing is drawn. So instead of analysing the whole SOAR terrain drawing, I just tried drawing 10 zero's in a LineStrip and noticed that even that didn't work ...

So the only code that get's executed in draw() is what's posted above. The vertexbuffer is filled with correct vertices : if I tell XNA to draw the whole vertexbuffer as points , the whole terrain shows up.





Re: XNA Framework indexbuffer is ignored

Kyle_W

One thing I noticed is that in your DrawIndexedPrimitives call, you are specifying that 10 vertices will be used and 10 primitives will be drawn. However there are two vertices per line primitive, so only 5 primitives should be drawn (when using a LineList). If you switched to using a LineStrip, then you would apparently specify the number of primitives as the number of vertices minus one according to the help file.



Re: XNA Framework indexbuffer is ignored

iljanated

ok , I figured it out :

the problem was that my vertexbuffer is 513 * 513 big , but I thought numVertices specifies the number of vertices in the primitive (10) ...

--> adjusted numVertices and it worked d'oh :-)

It's actually well explained int the reference docs but just looked over it ...