How to draw several separate lines using a single VBO?
Asked
Active
Viewed 5,123 times
2 Answers
19
glDrawElements(GL_LINES, ..., ..., ...);

genpfault
- 51,148
- 11
- 85
- 139
-
3Yup. There really is nothing else to it. This is the right answer. Each pair of points form one line. So, you can store unlimited lines in one huge VBO. – TheBuzzSaw Apr 28 '11 at 16:12
8
In OpenGL-3.1 and later there's a functionality called primitive restart. It works by specifying a special vertex array element index that causes the current primitive to be restarted. That way a single element array allows to draw several GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, GL_QUAD_STRIP.
http://www.opengl.org/sdk/docs/man4/xhtml/glPrimitiveRestartIndex.xml
This is largely based on the NV_primitive_restart extension: http://www.opengl.org/registry/specs/NV/primitive_restart.txt
Apart from that you can use a primitive type in which vertices are not shared and blow up the element index array a bit.

datenwolf
- 159,371
- 13
- 185
- 298
-
glDrawElements should be enough - plus as you say primative restart is not available in all versions. – paulm Feb 10 '14 at 13:27