• Advertisement
Sign in to follow this  

[SlimDX] Drawing vertexbuffer from mesh not working

This topic is 2988 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'm trying to directly draw the VertexBuffer of a Mesh object instead of calling Mesh.DrawSubset(). I use the code below:
    Device.SetRenderState<Cull>(RenderState.CullMode, Cull.None);
    mesh = Mesh.CreateBox(Device, 1.0f, 1.0f, 1.0f);
    Device.VertexFormat = VertexFormat.Position | VertexFormat.Normal;

// Stride seems ok. mesh.BytesPerVertex is 24 = sizeof(float)*6 = 24.
    Device.SetStreamSource(0, mesh.VertexBuffer, 0, mesh.BytesPerVertex);

// mesh.DrawSubset(0) would work ok here.
// mesh.FaceCount = 12.
// mesh.VertexCount = 24.
// I'm trying DrawPrimitives and DrawIndexedPrimitives below:
// Cubelike figure formed, but some triangles overlap/are wrong.
    Device.DrawPrimitives(PrimitiveType.TriangleList, 0, mesh.FaceCount);
// D3DERR_INVALIDCALL: Invalid call (-2005530516)
    Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, mesh.VertexCount, 0, mesh.FaceCount);

Thanks, Juan [Edited by - juanfhj on February 19, 2010 11:59:40 AM]

Share this post

Link to post
Share on other sites
This let me pinpoint the error.

With DrawIndexedPrimitives, the error is
Direct3D9: (ERROR) :No valid index stream currently set. DrawIndexedPrimitive failed.

So, I set

Device.Indices = mesh.IndexBuffer

I didn't do any locking. This seemed to work , so it's not necessary at all for buffers from meshes?

Thanks very much, Juan

[Edited by - juanfhj on February 19, 2010 11:14:39 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement