Skip to content

Commit

Permalink
Use GL_TRIANGLES instead of GL_TRIANGLE_STRIP
Browse files Browse the repository at this point in the history
The spectrum plot widget is made of quads, but they do not actually form a strip, so it was leading to some visual glitches. Use plain triangles instead.
  • Loading branch information
tlecomte committed Mar 23, 2018
1 parent 50be518 commit 82caee4
Showing 1 changed file with 46 additions and 32 deletions.
78 changes: 46 additions & 32 deletions friture/spectrumPlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,37 +356,51 @@ def prepareQuadData(self, x, y, w, baseline, r, g, b):

n = x.shape[0]

# 4 vertices per quad * (3 coordinates + 3 color coordinates)
if self.vertices_data.shape != (n*4, 6):
self.vertices_data = zeros((n*4, 6), dtype=np.float32)

self.vertices_data[0::4, 0::6] = x[:,np.newaxis]
self.vertices_data[0::4, 1::6] = (y + h)[:,np.newaxis]
self.vertices_data[0::4, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[0::4, 3::6] = r[:,np.newaxis]
self.vertices_data[0::4, 4::6] = g[:,np.newaxis]
self.vertices_data[0::4, 5::6] = b[:,np.newaxis]

self.vertices_data[1::4, 0::6] = (x + w)[:,np.newaxis]
self.vertices_data[1::4, 1::6] = (y + h)[:,np.newaxis]
self.vertices_data[1::4, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[1::4, 3::6] = r[:,np.newaxis]
self.vertices_data[1::4, 4::6] = g[:,np.newaxis]
self.vertices_data[1::4, 5::6] = b[:,np.newaxis]

self.vertices_data[2::4, 0::6] = x[:,np.newaxis]
self.vertices_data[2::4, 1::6] = y[:,np.newaxis]
self.vertices_data[2::4, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[2::4, 3::6] = r[:,np.newaxis]
self.vertices_data[2::4, 4::6] = g[:,np.newaxis]
self.vertices_data[2::4, 5::6] = b[:,np.newaxis]

self.vertices_data[3::4, 0::6] = (x + w)[:,np.newaxis]
self.vertices_data[3::4, 1::6] = y[:,np.newaxis]
self.vertices_data[3::4, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[3::4, 3::6] = r[:,np.newaxis]
self.vertices_data[3::4, 4::6] = g[:,np.newaxis]
self.vertices_data[3::4, 5::6] = b[:,np.newaxis]
# (1 quad = 2 triangles = 6 vertices) * (3 coordinates + 3 color coordinates)
if self.vertices_data.shape != (n*6, 6):
self.vertices_data = zeros((n*6, 6), dtype=np.float32)

self.vertices_data[0::6, 0::6] = x[:,np.newaxis]
self.vertices_data[0::6, 1::6] = (y + h)[:,np.newaxis]
self.vertices_data[0::6, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[0::6, 3::6] = r[:,np.newaxis]
self.vertices_data[0::6, 4::6] = g[:,np.newaxis]
self.vertices_data[0::6, 5::6] = b[:,np.newaxis]

self.vertices_data[1::6, 0::6] = (x + w)[:,np.newaxis]
self.vertices_data[1::6, 1::6] = (y + h)[:,np.newaxis]
self.vertices_data[1::6, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[1::6, 3::6] = r[:,np.newaxis]
self.vertices_data[1::6, 4::6] = g[:,np.newaxis]
self.vertices_data[1::6, 5::6] = b[:,np.newaxis]

self.vertices_data[2::6, 0::6] = x[:,np.newaxis]
self.vertices_data[2::6, 1::6] = y[:,np.newaxis]
self.vertices_data[2::6, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[2::6, 3::6] = r[:,np.newaxis]
self.vertices_data[2::6, 4::6] = g[:,np.newaxis]
self.vertices_data[2::6, 5::6] = b[:,np.newaxis]

self.vertices_data[3::6, 0::6] = x[:,np.newaxis]
self.vertices_data[3::6, 1::6] = y[:,np.newaxis]
self.vertices_data[3::6, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[3::6, 3::6] = r[:,np.newaxis]
self.vertices_data[3::6, 4::6] = g[:,np.newaxis]
self.vertices_data[3::6, 5::6] = b[:,np.newaxis]

self.vertices_data[4::6, 0::6] = (x + w)[:,np.newaxis]
self.vertices_data[4::6, 1::6] = y[:,np.newaxis]
self.vertices_data[4::6, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[4::6, 3::6] = r[:,np.newaxis]
self.vertices_data[4::6, 4::6] = g[:,np.newaxis]
self.vertices_data[4::6, 5::6] = b[:,np.newaxis]

self.vertices_data[5::6, 0::6] = (x + w)[:,np.newaxis]
self.vertices_data[5::6, 1::6] = (y + h)[:,np.newaxis]
self.vertices_data[5::6, 2::6] = 0*x[:,np.newaxis]
self.vertices_data[5::6, 3::6] = r[:,np.newaxis]
self.vertices_data[5::6, 4::6] = g[:,np.newaxis]
self.vertices_data[5::6, 5::6] = b[:,np.newaxis]

def transformUpdate(self):
self.need_transform = True
Expand Down Expand Up @@ -459,7 +473,7 @@ def glDraw(self, xMap, yMap, rect, vbo, shader_program):
color_offset = c_void_p(3 * sizeof(c_float))
GL.glVertexAttribPointer(0, 3, GL.GL_FLOAT, GL.GL_FALSE, stride, vertex_offset)
GL.glVertexAttribPointer(1, 3, GL.GL_FLOAT, GL.GL_FALSE, stride, color_offset)
GL.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, self.vertices_data.shape[0])
GL.glDrawArrays(GL.GL_TRIANGLES, 0, self.vertices_data.shape[0])
GL.glDisableVertexAttribArray(0)
GL.glDisableVertexAttribArray(1)
finally:
Expand Down

0 comments on commit 82caee4

Please sign in to comment.