Sign in to follow this  

DX9 Vbuffer Ibuffer question

Recommended Posts

Dynx    100
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 this post

Link to post
Share on other sites
Trillian    410
In your situation, an index buffer is barely beneficial. Try the following :

// Indices
k[0] = 0; k[1] = 1; // Connect vertex 0 to vertex 1 to
k[2] = 2; k[3] = 3; // vertex 2 to vertex 3 to
k[4] = 4; k[5] = 5; // vertex 4 to vertex 5 and back to
k[6] = 0; // vertex 0

// Draw call
0, // You'll basically always be using zero here
0, 6, // Starting from vertex 0, you're using all of your 6 vertices
0, // The first index you're using is index 0
6); // 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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this