Sign in to follow this  
B_old

MDX 2 - DrawUserPrimitives()

Recommended Posts

B_old    689
Hello, I'm trying to draw some line with DrawUserPrimitives() in MD3D 2. As I understand I need a GraphicsBuffer for that. But I can't figure out how to fill it with my data. I'm also wondering how I can tell the device about my vertexformat. Some advice would be nice, since some things seem to have changed in MDX 2 and the sdk samples use a earlier version.

Share this post


Link to post
Share on other sites
Demirug    884
You should use the generic version of a graphics buffer. This will allows you to use the write methods to add your vertexes.

You need to set your vertex format with the VertexFormat or VertexDeclaration property before you call any draw method.

PS: You should not use MDX 2 for a real project as it will never released in it’s current form. Better stay with MDX1 and wait for the XNA framework.

Share this post


Link to post
Share on other sites
B_old    689
Thanks, that was an interesting read.

I am trying to draw a line like this:


Vertex_Colored[] vertices = new Vertex_Colored[2];

vertices[0] = new Vertex_Colored();
vertices[0].pos = new Vector3(0, 0, -5);
vertices[0].color = Color.White.ToArgb();
vertices[1] = new Vertex_Colored();
vertices[1].pos = new Vector3(0, 0, 5);
vertices[1].color = Color.White.ToArgb();

GraphicsBuffer<Vertex_Colored> gb = new GraphicsBuffer<Vertex_Colored>(2);

gb.Write(vertices);

rdevice.device.VertexFormat = VertexFormats.Position | VertexFormats.Diffuse;
rdevice.device.DrawUserPrimitives(PrimitiveType.LineList, 1, gb);

gb.Dispose();



I can see a line. But it is black rather than white.
I did call this beforehand: device.SetTextureState(0, TextureStates.ColorOperation, false);


[Edited by - B_old on May 19, 2006 9:16:28 AM]

Share this post


Link to post
Share on other sites
wong_bo    128
I am really surprised that you are using a structure called Vertex_Colored. It seems like a user-defined structure. I don't think DirectX will be able to recognize it.

Since you are using MDX2, you can just use the build-in structure PositionColored and the code should be like this:

PositionColored[] vertices = new PositionColored[2];
vertices[0].Position = new Vector3(0, 0, -5);
vertices[0].Color = Color.White;
vertices[1].Position = new Vector3(0, 0, 5);
vertices[1].Color = Color.White;
GraphicsBuffer<PositionColored> gb = new GraphicsBuffer<PositionColored>(2);
gb.Write(vertices);

rdevice.device.VertexFormat = PositionColored.Format; rdevice.device.DrawUserPrimitives(PrimitiveType.LineList, 1, gb);

gb.Dispose();




Don't forget to declare
using Microsoft.DirectX.Direct3D.CustomVertex;

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