Newbie questions about drawing primitives

Started by
9 comments, last by Evil Steve 17 years, 7 months ago
Quote:Original post by n000b
A question though, every time I want to add another vertice, I need to change the size of the array in three places: when creating the array, when setting up the vertex buffer and when calling memcpy. Is there any way this value dynamic or anything so that it is easier to maintain? I know I can create a constant to hold the value so that I only have to change it in one place, it still seems a little annoying though.
It depends how exactly you're using your code. If your code is a static array you can do this:
Vertex g_pVertices[] = {   Vertex(...),   Vertex(...),   ...};// When you create the VB:pDevice->CreateVertexBuffer(..., sizeof(g_pVertices), ...);// When you copy the data:memcpy(pLock, g_pVertices, sizeof(g_pVertices));

Not that'll only work if you use a static array. Otherwise sizeof() will return the size of a pointer (usually 4) instead of the size of the array itself.

Quote:Original post by n000b
Also, am I correct in thinking that you can only create on vertex buffer? If so, how would you display multiple seperate objects to the screen? Just say I wanted to draw three seperate squares, how would I do this using DrawPrimitive?
You can use as many vertex buffers as you like, but for performance reasons, it's best to use as few as possible. A single Draw[Indexed]Primitive() call can only use one vertex buffer though. You can still do something like this, however:
pDevice->SetStreamSource(0, pVB);pDevice->DrawPrimitive(...);pDevice->SetStreamSource(0, pOtherVB);pDevice->DrawPrimitive(...);// Etc

This topic is closed to new replies.

Advertisement