Sign in to follow this  
juanfhj

[SlimDX] Drawing vertexbuffer from mesh not working

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

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