Jump to content
  • Advertisement
Sign in to follow this  
B_old

MDX 2 - DrawUserPrimitives()

This topic is 4431 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

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
Advertisement
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
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!