Sign in to follow this  
Captain Logic

Noob question re multiple vertex buffers

Recommended Posts

Captain Logic    121
Just starting with D3D and trying to get my head around the "correct" way to do things. Say I have a vertex buffer with 3 vertices representing a triangle, and I want to render 5 copies of this triangle on the screen in different locations (translations). Can I do a DrawPrimitive 5 times with 5 different world transformations with the same vertex buffer? Or do I need 5 different vertex buffers, one for each triangle, even though the vertex coords will be identical?

Share this post


Link to post
Share on other sites
Mushu    1396
You can (technically) do it either way, however since matrix transforms are much faster than switching between vertex streams, you should use just one buffer and render it multiple times with different transforms.

Using only one buffer also uses less memory. Which is good :D

Share this post


Link to post
Share on other sites
Captain Logic    121
Whenever I try the first method (single vertex buffer) I only get one triangle on the screen if I do 5 transforms, the render is at the location of the final transform. I don't get 5 images on the screen.

This is what i'm doing (pseudo-code) in my render method:

Clearscreen()
BeginScene()
SetFVF(...)
SetStream(...) // use the vertexbuffer

// Draw tri 1
D3DMatrixTranslation(...) // translate 2 units to the right
SetTransform() // world transform
DrawPrimitive(triangle ,0, 1)

// Draw tri 2
D3DMatrixTranslation(...) // translate 4 units to the right
SetTransform()
DrawPrimitive(triangle ,0, 1)

// repeat above 3 lines for 3 more tris, each translation 2 units further on

Present(...)
EndScene()

Only the final transform is rendered. How do I get all 5 triangles to render at the 5 different translations?

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