Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have diamond-shaped polygonal bullets. There are lots of them on the screen.

I did not want to create a vertex array for each, so I packed them into a single vertex array and they're all drawn at once.

| | bullet1.rgb | | bullet2.rgb

This is great for performance.. there is

struct Bullet
    vector<Vector3f*> verts ; // pointers into the vertex buffer
} ;

This works fine, the bullets can move and do collision detection, all while having their data in one place.

Except when a bullet "dies"

Then you have to clear a slot, and pack all the bullets towards the beginning of the array.

Is this a good approach to handling lots of low poly objects? How else would you do it?

share|improve this question
Wouldn't using a linked list instead of a vector work well? Then you can just pull out that one item, without needing to shift everything else. – Byte56 Sep 29 '12 at 18:16
I thought about using a linked list, but the underlying data needs to be an interleaved array with guaranteed contiguous storage that can be passed to the drawing API (glDrawArrays(), in this case) – bobobobo Sep 29 '12 at 18:37
up vote 4 down vote accepted

Then you have to clear a slot, and pack all the bullets towards the beginning of the array.

Don't shuffle all the bullets down toward the beginning of the array; just swap the last bullet into the newly cleared slot. That way you don't need to repack the whole vector; you only need to move a single element to fill the space that was made by the dead bullet.

share|improve this answer
Yes, I ended up doing this !:) – bobobobo Sep 30 '12 at 21:40

If the number of bullets is fixed at the start, then you can leave the vert data in the array. Create a second array that is a list of Booleans that represent each bullet. As a bullet dies flip the value in the second tracking array to false. Use this array as a filter for you vertex loop.

So if each bullet has 4 verts, the second array is 1/4 the size, with each boolean representing 1 bullet of 4 verts.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.