Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

The game I'm working on has OpenGL (2.1) vector graphics, and I need to draw up to 1000 enemies, each of which is composed of between 4 and 100 lines.

Each enemy can be drawn as a single line loop, so one strategy for drawing would be to call glDrawElements(GL_LINE_LOOP, ...) once for each enemy. This results in too many (up to 1000) calls of glDrawElements per frame.

Another strategy would be to separate the line-loops that form each enemy into individual line segments, and call glDrawElements(GL_LINES, ...). This results in a lot of repeated vertices though, which I would like to avoid.

Is there a way to draw multiple line loops in a single call to glDrawElements (or with some other function)? I guess I would need some indicator in the vertex/element array to mark where each line loop ended.

share|improve this question
up vote 1 down vote accepted

Surely if you're using indices, you're not repeating verts?

You could also look at instancing, where you have a set of primitives being repeatedly drawn with a set of matrices being sent at lower frequency (i.e. a single call could draw 20 lines, repeated with 15 different matrices).


It occurs to me that you might be worried about the duplication of indices rather than verts. I wouldn't worry about that - that's kind of the point of indices. They allow verts to be reused without being retransformed by the GPU.

share|improve this answer
Thanks - duplication (of either indices or vertices) was what I was worried about, but if that's the indented use of indices, I'm happy using those and plotting everything as separate lines. The other thing I was concerned about was artifacts at the vertices from plotting two separate lines rather than a GL_LINE_LOOP, since I'm using blending. For single-pixel-width lines though, this isn't an issue (at least on my hardware). – Chris Johnson Aug 17 '10 at 13:38

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.