Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Draw lines with VBO

Tags:

lines

opengl

vbo

How to draw several separate lines using a single VBO?

like image 793
itun Avatar asked Apr 28 '11 15:04

itun


2 Answers

glDrawElements(GL_LINES, ..., ..., ...);

like image 98
genpfault Avatar answered Oct 01 '22 06:10

genpfault


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.

like image 41
datenwolf Avatar answered Oct 01 '22 06:10

datenwolf