Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Question about DrawIndexedPrimitive

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having some trouble with DrawIndexedPrimitive, the data I am rendering uses dynamic vertices and indices so I have created a single large vertex buffer and a single large index buffer, the idea is to keep appending to them until they are full then discard them and start over using D3DLOCK_DISCARD on the Lock calls. The problem is nothing I am doing seems to work. Take the following example: Draw 3 triangles, consisting of 5 vertices, and 9 indices when broken down into a triangle list. The 5 vertices are offset 100 vertices into the vertex buffer, the 9 indices are offset 200 indices into the index buffer (and all contain values from 0 to 4). So I look up the docs for SetIndices which takes 2 paramaters, the first has to be my one and only index buffer, the second is described as: BaseVertexIndex: Base value for vertex indices. This value is added to all indices prior to referencing vertex data, defining a starting position in the vertex streams This I assume must be 100, which is where the vertices are in the vertex buffer, Next I come to draw primitive, Which lists its paramaters as: MinIndex Minimum vertex index for vertices used during this call. NumVertices The number of vertices indexed during this call, starting from BaseVertexIndex + StartIndex StartIndex Location in the index array to start reading indices. PrimitiveCount Number of primitives to render. The number of vertices used is a function of the primitive count and the primitive type. The maximum number of primitives allowed is determined by checking the MaxPrimitiveCount member of the D3DCAPS8 structure. Primitive count is easy since I want to draw 3 triangles. The others are causing me the headache. StartIndex seems to want the location in the index array to begin indexing, which I assume is 200 since my index data is 200 entries into the index buffer. Then the problems begin, NumVertices says it is the number of vertices indexed in this call, is that 5 because I use 5 vertices, or 9 because i use 9 indexes. Then it says that number depends on BaseVertexIndex (which is an offset into the vertex buffer) and StartIndex (which is an offset into the index buffer) how can it depend on both of those unrelated values? This leaves MinIndex, the minimum vertex index for vertices used in this call, which sounds very like the BaseVertexIndex paramater to SetIndices (I must note however that any values I pass here never seem to make the slightest bit of difference). I can get things working when either the vertex data or the index data is at the start of their respective buffers, but when both are offset it doesnt seem to work, and changing the values of some of these values when they are working makes no discernable difference so it is hard to be sure which of the values I am using are or arent correct. If anyone can explain exactly what these parameters represent I would be very grateful. Lastly I am using a geForce3 card, DirectX 8.1 and the latest nvidia drivers so if that makes any difference it would be nice to know. Thanks for Reading, Skulver

Share this post

Link to post
Share on other sites
number of vertices index in the call is exactly that. the number of vertices that will need to be transformed to draw the triangles (btw you should be drawing more then 3 per call, but thats another story).

you should try the following, dont rely on the setindices offset for your indecies, you know what the offset is so add it yourself. if that works, then you know it has to do with how setindices is doing stuff.

though from what i read, it looks like you need to (i assume you are using triangle lists due to the number of indexs and vertices, seems to me you should be using trianglestrips though without indexes):

SetIndices(indices, 100);
DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 5, 200, 3);

you probally tried it and had it not work, i will see later on if i can get it to work on my pc. also check the return error code that you get, maybe it will clue you in. if not you can try eliminating possible parms problems by specifing the minIdx to be 0 and the numVertices to be how many vertices are left in the vertex buffer (and are valid).

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!