def testOperator(self): m = QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) v = 1 for x in range(4): for y in range(4): self.assertEqual(m[x, y], v) v += 1
def _draw_lines(self): glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) glLineWidth(self.linewidth) self.program.bind() # we just retrieve the matrices from vsml. they are # updated from the Scene's transformation self.program.setUniformValueArray( self.projMatrix, QMatrix4x4(tuple(vsml.projection.ravel().tolist())), 16) self.program.setUniformValueArray( self.modelviewMatrix, QMatrix4x4(tuple(vsml.modelview.ravel().tolist())), 16) # http://www.pyside.org/docs/pyside/PySide/QtOpenGL/QGLShaderProgram.html glEnableVertexAttribArray(self.aPosition) glBindBuffer(GL_ARRAY_BUFFER, self.vertex_vbo) glVertexAttribPointer(self.aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0) glEnableVertexAttribArray(self.aColor) glBindBuffer(GL_ARRAY_BUFFER, self.colors_vbo[0]) glVertexAttribPointer(self.aColor, 4, GL_FLOAT, GL_FALSE, 0, 0) # bind the indices buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.connectivity_vbo) glDrawElements(GL_LINES, self.connectivity_nr, GL_UNSIGNED_INT, 0) self.program.disableAttributeArray(self.aPosition) self.program.disableAttributeArray(self.aColor) glBindBuffer(GL_ARRAY_BUFFER, 0) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) self.program.release()
def _draw_extruded(self): self.program.bind() self.program.setUniformValueArray( self.projMatrix, QMatrix4x4(tuple(vsml.projection.ravel().tolist())), 16) self.program.setUniformValueArray( self.modelviewMatrix, QMatrix4x4(tuple(vsml.modelview.ravel().tolist())), 16) self.program.setUniformValue(self.radiusSampler, 0) self.program.setUniformValue(self.viewportWidth, vsml.width) self.program.setUniformValue(self.viewportHeight, vsml.height) # http://www.pyside.org/docs/pyside/PySide/QtOpenGL/QGLShaderProgram.html self.program.enableAttributeArray(self.aPosition) glBindBuffer(GL_ARRAY_BUFFER, self.vertex_vbo) glVertexAttribPointer(self.aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0) glEnableVertexAttribArray(self.aColor) glBindBuffer(GL_ARRAY_BUFFER, self.colors_vbo[0]) glVertexAttribPointer(self.aColor, 4, GL_FLOAT, GL_FALSE, 0, 0) # bind the indices buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.connectivity_vbo) #glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_BUFFER_EXT, self.radius_unit) glDrawElements(GL_LINES, self.connectivity_nr, GL_UNSIGNED_INT, 0) self.program.disableAttributeArray(self.aPosition) self.program.disableAttributeArray(self.aColor) self.program.release()
def testMatrix4x4(self): self.assertRaises(TypeError, QMatrix4x4, [0.0, 1.0, 2.0, 3.0]) self.assertRaises(TypeError, QMatrix4x4, [ 0.0, 1.0, 2.0, 'I', 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 'N', 11.0, 12.0, 'd', 14.0, 'T' ]) my_data = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0 ] my_datac = [ 0.0, 4.0, 8.0, 12.0, 1.0, 5.0, 9.0, 13.0, 2.0, 6.0, 10.0, 14.0, 3.0, 7.0, 11.0, 15.0 ] m = QMatrix4x4(my_data) d = m.data() self.assert_(my_datac, d) d = m.copyDataTo() self.assert_(my_data == list(d))
def _pick_lines(self, x, y): if not self.enable_picking: print( "Picking not enabled. You need to set the ID parameter for the actor {0}" .format(self.name)) return # resize texture as well glBindTexture(GL_TEXTURE_2D, self.color_tex) blank = (GLfloat * (vsml.width * vsml.height * 4))() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, vsml.width, vsml.height, 0, GL_RGBA, GL_FLOAT, blank) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self.fbo) glPushAttrib(GL_VIEWPORT_BIT) glViewport(0, 0, vsml.width, vsml.height) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #glDisable(GL_BLEND) #glDisable(GL_MULTISAMPLE) glLineWidth(self.linewidth) # FBO render pass, need to use the selection id color array ################ self.program.bind() # we just retrieve the matrices from vsml. they are # updated from the Scene's transformation self.program.setUniformValueArray( self.projMatrix, QMatrix4x4(tuple(vsml.projection.ravel().tolist())), 16) self.program.setUniformValueArray( self.modelviewMatrix, QMatrix4x4(tuple(vsml.modelview.ravel().tolist())), 16) # http://www.pyside.org/docs/pyside/PySide/QtOpenGL/QGLShaderProgram.html glEnableVertexAttribArray(self.aPosition) glBindBuffer(GL_ARRAY_BUFFER, self.vertex_vbo) glVertexAttribPointer(self.aPosition, 3, GL_FLOAT, GL_FALSE, 0, 0) glEnableVertexAttribArray(self.aColor) glBindBuffer(GL_ARRAY_BUFFER, self.colors_vbo[1]) glVertexAttribPointer(self.aColor, 4, GL_FLOAT, GL_FALSE, 0, 0) # bind the indices buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.connectivity_vbo) glDrawElements(GL_LINES, self.connectivity_nr, GL_UNSIGNED_INT, 0) self.program.disableAttributeArray(self.aPosition) self.program.disableAttributeArray(self.aColor) glBindBuffer(GL_ARRAY_BUFFER, 0) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) self.program.release() ############ a = (GLfloat * 4)(0) glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, a) ID = (int(a[0] * 255) << 16) | (int(a[1] * 255) << 8) | int(a[2] * 255) glPopAttrib() glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0) if ID in self.current_selection: self.deselect(ID) else: self.select(ID) return ID