Skip to main content
GameDev.net gamedev.net
🔒 Locked

Noob question re multiple vertex buffers

Started by Captain Logic Oct 6, 2005 at 7:43 PM 1 replies 1.1k views
Original Post
Captain Logic
Captain Logic
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?
Mushu
Mushu
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
Captain Logic
Captain Logic
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.