   Drawing a range of Indexed Quads
  Here's a quick question, and here's the code I'm trying to modify to get it to do what I want:void DrawSprites(){UINT vNum = SP_END * 6;UINT iNum = vNum / 3;// Set up the texture...d3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );d3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );d3dDevice->SetTexture( 0, SpriteGroup.g_QuadsTB.Texture );// Now draw the primitives from the SpriteGroup structd3dDevice->SetStreamSource( 0, SpriteGroup.g_QuadsVB, 0, sizeof(CUSTOMVERTEX) );d3dDevice->SetIndices(SpriteGroup.g_QuadsIB);d3dDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST,0,0,vNum,0,iNum);}This is for a quad renderer for my game.  'SP_END' is 384 (the total number of quads in this index/vertex buffer).  The above function is rendering the entire vertex/index buffer.  However, I'd like to render about three or four ranges of this index buffer so I can use a different blending method and texture for each range (from 0 to 64, 64-128, 128-384).  I know it has something to do with 'DrawIndexedPrimitive', but I don't know how to calculate what vertex or index I want to start at, how many vertices I want to draw, etc.  Would any of you guys help me on this?Thanks in advance for the help! :)   
  From the April SDK the description of the DrawIndexedPrimitive shows the following:HRESULT DrawIndexedPrimitive(  D3DPRIMITIVETYPE Type,  INT BaseVertexIndex,  UINT MinIndex,  UINT NumVertices,  UINT StartIndex,  UINT PrimitiveCount);I would hazard a guess that you would put 0 in MinIndex, 0 in BaseVertexIndex and your selected start index in StartIndex.  However, BaseVertexIndex and NumVertices and Primitive Count might be the number of vertices and Primitves to draw during that cycle.Aha, reading further it shows the following:Type[in] Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render. D3DPT_POINTLIST is not supported with this method. See Remarks. BaseVertexIndex[in] Offset from the start of the vertex buffer to the first vertex. See Scenario 4.MinIndex[in] Minimum vertex index for vertices used during this call. This is a zero based index relative to BaseVertexIndex.NumVertices[in] Number of vertices used during this call. The first vertex is located at index: BaseVertexIndex + MinIndex.StartIndex[in] Index of the first index to use when accesssing the vertex buffer. Beginning at StartIndex to index vertices from the vertex buffer.PrimitiveCount[in] 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 D3DCAPS9 structure. Not sure whether that will help you but you might want to look into the SDK help file as it has some examples on drawing with the buffers.   ;  Thanks for the reply, Xrystal.  I researched what you've posted before, but I can't figure what formula to use to plug into 'UINT StartIndex' and 'UINT PrimitiveCount'.  I'm sure those two are what'll allow me to render a part of a vertex/index buffer, because I've experimented with various constants and was able to successfully render parts of my vertex/index buffer.  I just want to know what formula I can use to consistently draw a range of quads from my vertex/index buffer.  For example, when 'UINT vNum = SP_END * 6' and 'UINT iNum = vNum / 3' are used for 'UINT NumVertices' and 'UINT PrimitiveCount' respectively, I'm able to draw the entire vertex/index buffer (from 0 to SP_END).  I just can't figure out what to plug into 'UINT StartIndex' and 'UINT PrimitiveCount' to allow me to draw only a part of that same vertex/index buffer (for instance, from 128 to 256).  :(   ;  Here is a line from my program, where I redraw a single triangle from the mesh when I want it draw it with a different material.  I do this when a face is clicked on so that I can show it with a different color.pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mIWorkMesh->GetNumVertices(), mFaceIndexHit[index]*3, 1);The last two parameters determine the offset on the index buffer to start drawing and the number of faces to draw.  mFaceIndexHit has the DWORD returned by the D3DXIntersect that is the number of the face in the index buffer (0 = the first face).  Since each face in the index buffer indexes to the 3 vertices that make up that face, I multiply it by 3.  I only want to draw one face, so I put 1 in the last parameter.So, if you want to draw quads 0-63, you are really drawing faces 0-126 (127 of them).  You would do this:d3dDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST, 0,0, SP_END * 2, 0, 127);Then to draw the next 127:d3dDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST, 0,0, SP_END * 2, 127, 127);[Edited by - DXnut on June 3, 2006 4:21:46 PM];  Figuring out the correct DIP parameters can be "interesting" [lol] Also bare in mind that ATI drivers appear to be stricter than Nvidia when it comes to validating them. If you're developing on NV hardware, double-check your code against the reference rasterizer (or some ATI hardware if you have it available)...J Steed's classic blog entry (also in the SDK help files), DrawIndexedPrimitive Demystified, might be of interest...hthJack   ;Quote:Original post by DookieThanks for the reply, Xrystal.  I researched what you've posted before, but I can't figure what formula to use to plug into 'UINT StartIndex' and 'UINT PrimitiveCount'.  I'm sure those two are what'll allow me to render a part of a vertex/index buffer, because I've experimented with various constants and was able to successfully render parts of my vertex/index buffer.  I just want to know what formula I can use to consistently draw a range of quads from my vertex/index buffer.  For example, when 'UINT vNum = SP_END * 6' and 'UINT iNum = vNum / 3' are used for 'UINT NumVertices' and 'UINT PrimitiveCount' respectively, I'm able to draw the entire vertex/index buffer (from 0 to SP_END).  I just can't figure out what to plug into 'UINT StartIndex' and 'UINT PrimitiveCount' to allow me to draw only a part of that same vertex/index buffer (for instance, from 128 to 256).  :(Okay lets see .. how about something like thisvoid DrawSprites(){UINT vNum = SP_END * 6;UINT iNum = vNum / 3;   for (int i=0; i < iNum; i+=4)   {  if (i < iNum/4) DrawSprite(1,i,iNum,vNum);  else if (i < iNum/3) DrawSprite(2,i,iNum,vNum);  else if (i < iNum/2) DrawSprite(3,i,iNum,vNum);  else if (i < iNum)   DrawSprite(4,i,iNum,vNum);   }}void DrawSprite(int Stage,int iStart,int iCount,int vCount){   if (Stage == 1) etc   {   // Set up the texture as per Stage   d3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );   d3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );   d3dDevice->SetTexture( 0, SpriteGroup.g_QuadsTB.Texture );   }// Now draw the primitives from the SpriteGroup structd3dDevice->SetStreamSource( 0, SpriteGroup.g_QuadsVB, 0, sizeof(CUSTOMVERTEX) );d3dDevice->SetIndices(SpriteGroup.g_QuadsIB);   UINT vStart = Earliest Vertex Array Element to use in this drawing routine maybe another routine to quickly locate the earliest array index and return it here.   d3dDevice->DrawIndexedPrimitive (D3DPT_TRIANGLELIST,0,vStart,vNum,iStart,iCount/4);    }Not got this running in code form but theoretically it may well do what you want.   Good Luck.   ;  Thanks for all the replies, guys!  I'll experiment with all the ideas you gave me and find out what works best for my game.Heh, it's interesting that you mentioned the differences between Nvidia and ATI video cards, jollyjeffers.  I ran into that EXACT same problem some time ago.  I bought a brand-spanking new Nvidia GeForce 6800 when it came out (so I could play Doom 3 in all its gory - er, glory), then later wrote some indexed quad code for my game.  The new video code ran fine on my system, but later found out that it only worked on Nvidia-based machines.  It didn't work on anybody else's machine at all...  All quads rendered from indexed vertex buffers didn't render.  Sheesh!  It took a while to figure out that the problem was because I was developing my code on a Nvidia-based system, so it was a real head-scratcher to debug.  When I finally realized what was going on, I reinstalled my old Radeon 9600 Pro and installed the 6800 in my wife's computer, and I've never had any more complaints about my 'video' code not rendering on beta testers' computers.  Pretty strange stuff!Thanks again for all the great ideas!   