Archived

This topic is now archived and is closed to further replies.

Sardius2

Creating two objects with vertices?

Recommended Posts

Sardius2    122
Okay, after looking at tutorials I can create a triangle with vertices and the vertex buffer, and I can make a square, but I can''t manage to do both at once. What do I have to do to make both at the same time?

Share this post


Link to post
Share on other sites
dclyde    126
What do you mean exactly?

If you mean like a square and a triangle in the same buffer you can easily do soe by just putting them both into the same buffer end to end and then using two seperate DrawPrimitive/DrawIndexedPrimitive calls, unless its a triangle list in which you can do it with one.

// Full Sail Student with a passion for games
// This post in no way indicates my being awake when writing it

Share this post


Link to post
Share on other sites
Sardius2    122
Yeah, I want to draw a triangle and a square. But I dont know if i have to create two seperate vertex holders, or if I can put all 7 vertex points in the same array. I want them in the same buffer if possible. How do I do this calling DrawPrimitive twice? Or this DrawIndexedPrimitive?

Share this post


Link to post
Share on other sites
KershAtWork    122
Since a vertex buffer is just that, a buffer, you can put whatever kinds of vertices you want in there. If you put all seven vertices in there, it is up to the DrawPrimitive to determine what and how to draw.

If you have the first four vertices as the square and the next three as the triangle then all you would have to do is to SetStreamSource on the VB and do the following:

// Draw the square starting from the first data in the VB
DEVICE->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

// Draw the triangle starting from the triangle data
DEVICE->DrawPrimitive(D3DPT_TRIANGLELIST, 4, 1);

Remember that in the VB vertex 0, 1, 2, 3 make up the Square, and 4, 5, 6 make up the triangle.

You could always create another vertex buffer for the triangle. The problem is that as you start making more and more high polygonal models, you will want to batch all of your vertices into a single VB for processing and draw them together. Calling SetStreamSource for a single VB and drawing all models in the VB allows that VB to be prepared (moving to video memory possibly) once.

Good luck!

Share this post


Link to post
Share on other sites
KershAtWork    122
You probably knew this, but if you are going to add three more vertices to your vertex buffer, make sure that you allocate enough memory to hold these vertices in the call to CreateVertexBuffer!

CreateVertexBuffer(7 * sizeof(VERTEX) .. )

Share this post


Link to post
Share on other sites
Sardius2    122
Alright, Im understanding how to do this now, but the square still will not appear. It only draws one triangle of the square. Im using the triangle strip, im not sure why it doesn''t. I opened the dx sdk 9 and opened their vertice tutorial and changed the vertices to a square, changed the 4*sizeof part, and changed the drawprimitive to trianglestrip, 0, 2. But only half the triangle appears..any reason for this?

Share this post


Link to post
Share on other sites
Asim    122
if you change

D3DPT_TRIANGLESTRIP, 0, 2

to

D3DPT_TRIANGLESTRIP, 0, 3

it should work.

Since you are using D3DPT_TRIANGLESTRIP in the DrawPrimitive call I'm assuming your triangle and square are meant to be joined together. If not, then consider using D3DPT_TRIANGLELIST instead, although you will probably have to specify more vertices in order to do this (9 in fact - 3 for the triangle and 6 for the two triangles that make up the square)

Hope this helps

Asim

[edited by - asim on August 14, 2003 7:20:49 PM]

Share this post


Link to post
Share on other sites