Jump to content
  • Advertisement
Sign in to follow this  
ahmedsalah

Using Vertex buffer

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

Hi there, Right now i know how to load all the vertices into the vertex buffer and present it on the screen. The problem is the vertex buffer links all the vertices together in one mesh, i want to be able to draw separate squares and cubes. I tried to load the vertices of each square into the vertex buffer then presenting it, and then clear the buffer and load the vertices of the next square and present it and so on, but this was too slow because of locking and unlocking the vertex buffer all the time. I need to be able to load all the vertices into the vertex buffer at once but to also specify which vertices are linked together to make a square. I am using C#. I would appreciate any help, thank you.

Share this post


Link to post
Share on other sites
Advertisement
I havn't used MDX but im sure the rendering functions will be similar to those of unmanaged, if so you should be rendering your primitives (assuming your not using a index buffer) with a call to DrawPrimitives?

DrawPrimitive has 3 arguments, the first parameter you pass is the PrimitiveType(tirangle list, triangle strip etc...) the second parameter is the starting vertex in your vertex buffer and the last parameter is how many primitives you want to render.

So if your VB had 6 vertices specifying 2 seperate triangles, the first 3 vertices making up the first triangle and the last 3 vertices for the second triangle. To render the first triangle only you would use TriangleList as the Primitive Type argument, 0 for the starting vertex and 1 for the number of primitives to draw.

// Render the first triangle (first 3 vertices (v0, v1, v2))
device.DrawPrimitive(PrimitiveType.TriangleList, 0, 1);

And to render the second triangle only you would use:

// Render the second triangle (last 3 vertices (v3, v4, v5))
device.DrawPrimitive(PrimitiveType.TriangleList, 3, 1);

If at some point you wanted to render both triangles at the same time then you want to render 2 primitives:

// Render all the vertices in the vb (v0, v1, v2, v3, v4, v5)
device.DrawPrimitive(PrimitiveType.TriangleList, 0, 2);

[Edited by - cNoob on June 7, 2008 1:58:29 PM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!