0

so I have managed to draw 2 lines (consisting of 5 smaller 'line segments' each) directly from a VBO, however it connects the two lines when it shouldn't.

So the code for drawing the lines consists of:

self.linelist = np.array([
                          # LINE 1 #
                          [  50., 350., 150.,  94.], #Segment 1
                          [ 150.,  94., 250., 392.], #Segment 2
                          [ 250., 392., 350., 466.], #Segment 3
                          [ 350., 466., 450., 233.], #Segment 4
                          [ 450., 233., 550., 420.], #Segment 5
                          [ 550., 420.,  50., 490.], #Joining Segment
                          # LINE 2 #
                          [  50., 490., 150.,  94.], #Segment 1
                          [ 150.,  94., 250., 280.], #Segment 2
                          [ 250., 280., 350., 280.], #Segment 3
                          [ 350., 280., 450., 419.], #Segment 4
                          [ 450., 419., 550., 140.]  #Segment 5
                         ], dtype=np.float32)

self.linevbo = glvbo.VBO(self.linelist)

self.linevbo.bind()

glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(2, GL_FLOAT, 0, self.linevbo)

self.faces = np.array(range((len(self.linelist)*2)), dtype=np.uint32)

glDrawArrays(GL_LINES, 0, len(self.linelist)*2)

glDisableClientState(GL_VERTEX_ARRAY)

How can I stop it from joining the two lines?

EDIT: I think I need to use glMultiDrawArrays but I have no idea how to...

James Elder
  • 1,583
  • 3
  • 22
  • 34

1 Answers1

0

I've found the answer. The documentation on the internet seems to be either vague or difficult to understand, but the solution is to add a fourth parameter to glDrawArrays specifying the number of lines (in my case line segments) to be drawn, and also to remove the line in self.linelist which specifies the joining segment.

i.e.

self.linelist = np.array([
                          # LINE 1 #
                          [  50., 350., 150.,  94.], #Segment 1
                          [ 150.,  94., 250., 392.], #Segment 2
                          [ 250., 392., 350., 466.], #Segment 3
                          [ 350., 466., 450., 233.], #Segment 4
                          [ 450., 233., 550., 420.], #Segment 5
                          # LINE 2 #
                          [  50., 490., 150.,  94.], #Segment 1
                          [ 150.,  94., 250., 280.], #Segment 2
                          [ 250., 280., 350., 280.], #Segment 3
                          [ 350., 280., 450., 419.], #Segment 4
                          [ 450., 419., 550., 140.]  #Segment 5
                         ], dtype=np.float32)

glDrawArrays(GL_LINES, 0, len(self.linelist)*2, len(self.linelist))

EDIT: Actually it seems the fourth parameter to glDrawArrays is not required however perhaps it is good practice to specify it?

James Elder
  • 1,583
  • 3
  • 22
  • 34