# DX9 Vbuffer Ibuffer question

This topic is 3891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I thought I figured out how DrawIndexedPrimitive works until it completely confused me 10 minutes ago. I was trying to draw an arbitrary polygon. It has 6 sides and 6 vertices. So basically you start with a vertex and play connect the dots pretty much an voila! there is the polygon. In case you want to picture it: Vertices: v[0] = VertexPos(-1.0f, 2.0f, 1.0f); v[1] = VertexPos(2.0f, 1.75f, 1.0f); v[2] = VertexPos( 1.0f, 0.0f, 1.0f); v[3] = VertexPos( 3.0f, -0.25f, 1.0f); v[4] = VertexPos(0.0f, -2.0f, 1.0f); v[5] = VertexPos(-2.0f, 1.0f, 1.0f); Indices: k[0] = 0; k[1] = 1; k[2] = 1; k[3] = 2; k[4] = 2; k[5] = 3; k[6] = 3; k[7] = 4; k[8] = 4; k[9] = 5; k[10] = 5; k[11] = 0; So, I figured, to the "number of vertices" paramter of the function, I needed to pass 6 vertices since there are 6. Also for the "number of primitives", I thought I should pass 6 again, because it has 6 sides. And I am using line strips. However it didn't completely draw my shape. So I decided to play with numbers, completely confused and found out that the least parameters that work are like this: HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP, 0, 0, 0, 0, 11)); Can somebody explain to me, why even though I pass 0 vertices, it draws the whole shape and why I need to pass at least 11 primitives? Thanks

##### Share on other sites
In your situation, an index buffer is barely beneficial. Try the following :

// Indicesk[0] = 0; k[1] = 1; // Connect vertex 0 to vertex 1 tok[2] = 2; k[3] = 3; // vertex 2 to vertex 3 tok[4] = 4; k[5] = 5; // vertex 4 to vertex 5 and back tok[6] = 0; // vertex 0// Draw callgd3dDevice->DrawIndexedPrimitive(D3DPT_LINESTRIP,0, // You'll basically always be using zero here0, 6, // Starting from vertex 0, you're using all of your 6 vertices0, // The first index you're using is index 06); // You're going to draw 6 primitives (6 lines)

EDIT : As for why it draws even if you specify 0 vertices, you should know that, when drawing indexed primitives, the vertices you specify are only a hint to the graphics driver so it knows which vertices will be indexed by your draw call. If you pass 0 vertices, I bet that the driver consider that any vertex in your vertex buffer could be indexed. It's a simple matter of optimization.

EDIT 2 : The way you defined your indices, by pairs of two points, corresponds to the D3DPT_LINELIST primitive type, not the D3DPT_LINESTRIP primitive type. More on this on msdn

Oh I see.
Thanks!

##### Share on other sites
What you were making was a LINELIST. In a linelist, you can have seperate unconnected lines, and requires the extra indices to point out all the start and end points.

1. 1
Rutin
26
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 10
• 10
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631752
• Total Posts
3002091
×