Some confusion with Vertex Buffers (D3D)

dallasstar

New member
Suppose I have 2 objects:

a triangle and a square

i need to put them both in a vertex buffer before rendering. (or at least that's what i think)

so.... do I need two vertex buffers or can i render them with just one?

Whatever the answer, could somebody give me a breif explanation o n how i would go abour rendering both objects? (just the part that i would need to create the vertex buffer(s) and how to handle these while rendering the objects)

(before doing this, my programs all had objects of the same number of vertices)
 
Ok, I'm an OpenGL programmer, but looking at the documentation and a tutorial, it's not much different. . .

You can put them in the same vertex buffer if you want, but then you just have to keep track of where it is in the buffer. If you're using DrawPrimative to render the objects, you'll notice that the second parameter is the index of the first vertex you want to render and the third parameter is the number of primatives you want to render. Thus:

Code:
DrawPrimative (D3DPT_TRIANGLELIST, 0, 1);
DrawPrimative (D3DPT_TRIANGLEFAN, 3, 2);

That is, assuming you're using a triangle fan to draw the square. The primative count for the square is 2, because a single primative for triangle fans is a single triangle, the square being made up of two triangles (taking up a total of four vertices).

Of course, when you create the vertex buffer you'll have to toss in both the triangle's vertices and the square's vertices at the same time.
 
Last edited:
Back
Top