   How to:Create Meshes from Vertices?
  Good Day,I have made some basic 3d shapes, namely a cube-like object using Vertices and Vertex Buffers.I present those shapes using the d3ddev->SetStreamSource(...);d3ddev->DrawPrimitive(D3DPT_TRIANGLEFAN,...);functions.Now i want to "save" these shapes in a mesh, so i can draw them more easily with mesh.DrawSubset(0).I tried to create the mesh using:D3DXCreateMeshFVF(...);but unfortunately i am doing something wrong, as nothing is displayed with themesh.DrawSubset(0) function.Any help on how i can create this mesh from my vertex buffer would be great!Thanx in advance,Stakon.   
  Check the return values from your functions to ensure that none of the DirectX calls are returning errors. Also, note that DrawSubset() requires that you have an index buffer for your polygons - without an index buffer the mesh code won't render anything. I didn't see any mention of the index buffer in your code, so I'm assuming that's what's missing.   ;  The return value is S_OK so i think the mesh is created, or at least there is no problem with the parameters i give.As for the index buffer, you are correct.I hadn't set any.Now that  i read the specifics of the index buffer it seems i have to draw the whole mesh triangle by triangle...Is there an easier way, ie. setting the index buffer using an equivalent of TRIANGLEFAN,TRIANGLELIST etc.?Also i read it the index buffer must have the vertices drawn in clockwise order.This can become tedious, so is there any way to draw both clockwise and counter-clockwise at the same time (like SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE) ) ?Thanx in advance,Stakon.   ;  I didn't see this mentioned, so I don't know if you're doing it and didn't mention it, or not doing it at all but, after you create the mesh with D3DXCreateMeshFVF() you still have to copy the vertex and index information into the newly created mesh.  This is done the same way you copy vertex and index information into vertex/index buffers you create on your own.The mesh you create has a LockVertexBuffer() and LockIndexBuffer() method.  Lock each buffer, memcpy the information into the buffer, then unlock it.  Only after these steps are done will your newly create mesh actually contain a mesh to Draw.   ;Quote:Original post by stakonAs for the index buffer, you are correct.I hadn't set any.Now that  i read the specifics of the index buffer it seems i have to draw the whole mesh triangle by triangle...The index buffer just adds another level of indirection. Instead of getting the next 3 vertices, you get the next 3 indices, see what vertex numbers they are, and grab them.Quote:Original post by stakonIs there an easier way, ie. setting the index buffer using an equivalent of TRIANGLEFAN,TRIANGLELIST etc.?Nope. You've probably realised this by now, but ID3DXMesh really isn't designed to be used to create meshes at runtime; it's more for creating offline, and then loading into your app from a file or other resource.Quote:Original post by stakonAlso i read it the index buffer must have the vertices drawn in clockwise order.This can become tedious, so is there any way to draw both clockwise and counter-clockwise at the same time (like SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE) ) ?Yes, that'll work, but it's less efficient. The point is that if triangles are always specified in clockwise order, the GPU can not bother rendering any triangles that are specified in an anti-clockwise order, since that means they're facing away from the camera:If you disable backface culling, then the GPU will have to draw all triangles, even if they're facing away from the camera, which is more work to do.   