def drawEEGPositions(self, points, names): genList = GL.glGenLists(1) GL.glNewList(genList, GL.GL_COMPILE) for point, name in zip(points, names): normal = self.skin_surf.projectPoint(point, smooth=False)[1] if normal is None or normal == [] or point is None or point == []: print('Invalid Point!') else: u, v = self.skin_surf.getTangentCoordinates(normal) pos_el = point + 2 * normal GL.glEnable(GL.GL_LIGHTING) self.qglColor(GREEN) self.ellipse(pos_el, normal, u, v, [6, 6]) if bool(GLUT.glutBitmapString): pos_text = point + 5 * normal GL.glDisable(GL.GL_LIGHTING) GL.glColor3f(0.0, 0.0, 0.0) GL.glRasterPos3f(*pos_text) GLUT.glutBitmapString(GLUT.GLUT_BITMAP_HELVETICA_12, name.encode()) GL.glEnable(GL.GL_LIGHTING) GL.glEndList() self.eegPositions = genList self.update()
def drawLabel(self, text, x, y, font=glut.GLUT_BITMAP_9_BY_15, c=[1.0, 1.0, 1.0]): gl.glRasterPos2f(int(x), int(y)) glut.glutBitmapString(font, text)
def paintGL(self, ci, cameraInterest, p0=0, p1=None, drawOpts=DRAWOPT_DETECTIONS): ''' :param drawOpts: OR combination of draw flags. default is :data:`UI.DRAWOPT_DETECTIONS` ''' if ci < 0 or ci + 1 >= len(self.bounds): return if not DRAWOPT_DETECTIONS & drawOpts or not self.visible: return if p1 is None or p1 > self.len(ci): p1 = self.len(ci) x, s = self.vertices, self.bounds x2ds = x[s[ci]:s[ci + 1]][p0:p1] plot = np.zeros((len(x2ds), 3), dtype=np.float32) plot[:, :2] = x2ds plot[:, 2] = -1.0 plot *= cameraInterest GL.glDisable(GL.GL_DEPTH_TEST) GL.glPointSize(self.pointSize) GL.glEnable(GL.GL_BLEND) if self.colours.any(): GL.glEnableClientState(GL.GL_COLOR_ARRAY) GL.glColorPointerf(self.colours[s[ci]:s[ci + 1]][p0:p1]) else: GL.glColor4f(*self.colour) GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glVertexPointerf(plot) GL.glDrawArrays(GL.GL_POINTS, 0, len(plot)) GL.glDisableClientState(GL.GL_VERTEX_ARRAY) GL.glEnable(GL.GL_DEPTH_TEST) GL.glDisable(GL.GL_BLEND) GL.glDisableClientState(GL.GL_COLOR_ARRAY) drawLabels = DRAWOPT_LABELS & drawOpts if self.names is not None and drawLabels: nameWidth = [ sum([GLUT.glutBitmapWidth(self.font, ord(x)) for x in name]) for name in self.names ] GL.glColor4f(*self.fontColour) Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) for name, v, w in zip(self.names, self.vertices, nameWidth)[s[ci]:s[ci + 1]][p0:p1]: if bool(GL.glWindowPos2f): p = GLU.gluProject(v[0], v[1], -1.0, Mmat, Pmat, viewport) GL.glWindowPos2f(p[0] - 0.5 * w, p[1]) else: GL.glRasterPos3f(v[0], v[1] + 10, v[2]) GLUT.glutBitmapString(self.font, name)
def paintGL(self, p0=0, p1=None, drawOpts=DRAWOPT_DEFAULT): ''' :param drawOpts: OR combination of draw flags. default is :data:`UI.DRAWOPT_DEFAULT` ''' is_click = (p1 is not None) if p1 is None: p1 = len(self) assert(p0 >= 0 and p1 >= p0 and p1 <= len(self.vertices)) if p1 <= p0: return # draw nothing GL.glDisable(GL.GL_TEXTURE_2D) GL.glShadeModel(GL.GL_SMOOTH) GL.glColor3f(*self.color) GL.glLineWidth(1) GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glVertexPointerf(self.vertices) GL.glDrawElementsui(GL.GL_LINES, self.idx) if self.graph is not None: GL.glColor3f(0,1,0) GL.glLineWidth(5) GL.glVertexPointerf(self.vertices) GL.glDrawElementsui(GL.GL_LINES, self.graph) GL.glColor3f(1,0,0) GL.glPointSize(10) GL.glVertexPointerf(self.vertices) GL.glDrawArrays(GL.GL_POINTS, 0, len(self.vertices)) if self.name and DRAWOPT_LABELS & drawOpts: GL.glColor3f(*self.color) phi = np.max(self.vertices,axis=0) plo = np.min(self.vertices,axis=0) if bool(GL.glWindowPos2f): Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) p = GLU.gluProject((phi[0]+plo[0])*0.5,phi[1] + 300.0,(phi[2]+plo[2])*0.5, Mmat, Pmat, viewport) if self.nameWidth is None: self.nameWidth = sum([GLUT.glutBitmapWidth(self.font, ord(x)) for x in self.name]) GL.glWindowPos2f(p[0] - 0.5*self.nameWidth,p[1]) else: GL.glRasterPos3f((phi[0]+plo[0])*0.5,phi[1] + 300.0,(phi[2]+plo[2])*0.5) GLUT.glutBitmapString(self.font, self.name) if self.names and DRAWOPT_LABELS & drawOpts: if self.nameWidths is None: self.nameWidths = [sum([GLUT.glutBitmapWidth(self.font, ord(x)) for x in name]) for name in self.names] GL.glColor3f(*self.color) Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) for ni,(name,v,w) in enumerate(zip(self.names, self.vertices, self.nameWidths)): if bool(GL.glWindowPos2f): p = GLU.gluProject(v[0],v[1]+10+ni*0.1,v[2], Mmat, Pmat, viewport) GL.glWindowPos2f(p[0] - 0.5*w,p[1]) else: GL.glRasterPos3f(v,(phi[2]+plo[2])*0.5) GLUT.glutBitmapString(self.font, name) GL.glDisableClientState(GL.GL_VERTEX_ARRAY)
def draw_node_labels(pos,nodelist,node_labels,node_label_font,node_label_colors): GL.glDisable(GL.GL_DEPTH_TEST) GL.glColor(*node_label_colors[0]) #Seems to be a bug i = 0 for n in nodelist: GL.glRasterPos(*pos[n]) GL.glColor(*node_label_colors[i]) # JJB - hack workaround try: GLUT.glutBitmapString(node_label_font[i],node_labels[i]) except: pass i+=1 GL.glEnable(GL.GL_DEPTH_TEST)
def draw_edge_labels(pos,edgelist,edge_labels,edge_label_font,edge_label_colors): GL.glDisable(GL.GL_DEPTH_TEST) GL.glColor(*edge_label_colors[0]) #Seems to be a bug k = 0 for (i,j) in edgelist: position = [] for d in range(len(pos[i])): position.append((pos[i][d]+pos[j][d])/2.) position = tuple(position) GL.glRasterPos(*position) GL.glColor(*edge_label_colors[k]) try: GLUT.glutBitmapString(edge_label_font[k],edge_labels[k]) except: pass k+=1 GL.glEnable(GL.GL_DEPTH_TEST)
def drawText(self, x, y, s, font=GLUT.GLUT_BITMAP_TIMES_ROMAN_10, color=None): if color is None: color = self.textColor if bool(GL.glWindowPos2f): GL.glColor3f(color[0],color[1],color[2]) GL.glWindowPos2f(x, self.height-y) GLUT.glutBitmapString(font, s) else: GL.glDisable(GL.GL_TEXTURE_2D) GL.glColor3f(color[0],color[1],color[2]) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GLU.gluOrtho2D(0.0, self.width, self.height, 0.0) # (0,0) at top-left GL.glRasterPos2f(x, y) GLUT.glutBitmapString(font, s) GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPopMatrix()
def RenderText(self, text, x, y): GL.glColor3f(1.0, 0.0, 0.0) GL.glWindowPos2f(x, y) GLUT.glutBitmapString(GLUT.GLUT_BITMAP_HELVETICA_10, text)
def drawHeatMapScale(self, field): GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GL.glOrtho(-60, 60, -60, 60, 0, 200) # GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glDisable(GL.GL_LIGHTING) if bool(GLUT.glutBitmapString): GL.glColor3f(0.0, 0.0, 0.0) GL.glRasterPos2i(26, -58) GLUT.glutBitmapString(GLUT.GLUT_BITMAP_HELVETICA_12, f"{max(field) : .2f}".encode()) GL.glRasterPos2i(-32, -58) GLUT.glutBitmapString(GLUT.GLUT_BITMAP_HELVETICA_12, f"{min(field) : .2f}".encode()) GL.glRasterPos2i(-5, -58) GLUT.glutBitmapString(GLUT.GLUT_BITMAP_HELVETICA_12, "dA/dt (V/m)".encode()) top = -50 bot = -55 GL.glBegin(GL.GL_QUAD_STRIP) GL.glColor3f(0, 0, 0.5) GL.glVertex2f(-30, top) GL.glVertex2f(-30, bot) GL.glColor3f(0, 0, 1) GL.glVertex2f(-22.5, top) GL.glVertex2f(-22.5, bot) GL.glColor3f(0, 1, 1) GL.glVertex2f(-7.5, top) GL.glVertex2f(-7.5, bot) GL.glColor3f(0.5, 1, 0.5) GL.glVertex2f(0, top) GL.glVertex2f(0, bot) GL.glColor3f(1, 1, 0) GL.glVertex2f(7.5, top) GL.glVertex2f(7.5, bot) GL.glColor3f(1, 0, 0) GL.glVertex2f(22, top) GL.glVertex2f(22, bot) GL.glColor3f(0.5, 0, 0) GL.glVertex2f(30, top) GL.glVertex2f(30, bot) GL.glEnd() GL.glEnable(GL.GL_LIGHTING) GL.glPopMatrix() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW)
def paintGL(self, p0=0, p1=None, drawOpts=DRAWOPT_DEFAULT): ''' :param drawOpts: OR combination of draw flags. default is :data:`UI.DRAWOPT_DEFAULT` ''' if not DRAWOPT_CAMERAS & drawOpts: return if p1 is None: p1 = len(self) if self.colour[3] != 1: GL.glDisable(GL.GL_DEPTH_TEST) # looks much better GL.glEnable(GL.GL_BLEND) GL.glColor4f(*self.colour) if p1 > p0: GL.glPointSize(5) if self.transform is not None: GL.glPushMatrix() GL.glMultMatrixf(self.transform.T) for pi in xrange(p0, p1): GL.glPushMatrix() GL.glMultMatrixf(self.transforms[pi].T) if self.colours is not None and pi < len(self.colours): GL.glColor4f(*self.colours[pi]) self.drawCamera(drawOpts) ''' GL.glMultMatrixd(np.linalg.inv(self.cameras[pi].K().T)) x = y = z = self.cameras[pi].cameraInterest xn = yn = zn = self.cameras[pi].cameraInterest * 0.200002 cpts = np.array([[-x, -y, -z], [x, -y, -z], [x, y, -z], [-x, y, -z], [-xn, -yn, -zn], [xn, -yn, -zn], [xn, yn, -zn], [-xn, yn, -zn]], dtype=np.float32) self.cameraFrustrumArray = np.array([cpts[0], cpts[1], cpts[1], cpts[2], cpts[2], cpts[3], cpts[3], cpts[0], cpts[4], cpts[5], cpts[5], cpts[6], cpts[6], cpts[7], cpts[7], cpts[4], cpts[0], cpts[4], cpts[1], cpts[5], cpts[2], cpts[6], cpts[3], cpts[7] ], dtype=np.float32) * .2 self.cameraFrustrumIdxArray = np.arange(0, len(self.cameraFrustrumArray)) self.drawFrustrum() ''' GL.glPopMatrix() if self.transform is not None: GL.glPopMatrix() # camera labels if self.names is None or not (DRAWOPT_LABELS & drawOpts): return if self.nameWidth is None: self.nameWidth = [ sum([GLUT.glutBitmapWidth(self.font, ord(x)) for x in name]) for name in self.names ] Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) for name, mat, w in zip(self.names, self.mats, self.nameWidth)[p0:p1]: try: v = mat[4] if bool(GL.glWindowPos2f): p = GLU.gluProject(v[0], v[1] + 10, v[2], Mmat, Pmat, viewport) if p[2] > 1 or p[2] < 0: continue # near/far clipping of text GL.glWindowPos2f(p[0] - 0.5 * w, p[1]) else: GL.glRasterPos3f(v[0], v[1] + 10, v[2]) GLUT.glutBitmapString(self.font, name) except ValueError: pass # projection failed
def paintGL(self, p0=0, p1=None, drawOpts=DRAWOPT_DEFAULT): ''' :param drawOpts: OR combination of draw flags. default is :data:`UI.DRAWOPT_DEFAULT` ''' if not self.visible: return if self.vertices is None or len(self.vertices) == 0: return #print self.vertices.shape is_click = (p1 is not None) if p1 is None: p1 = len(self) assert (p0 >= 0 and p1 >= p0 and p1 <= len(self.vertices)) if p1 <= p0: return # draw nothing GL.glDisable(GL.GL_LIGHTING) GL.glDisable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_BLEND) GL.glShadeModel(GL.GL_FLAT) if self.normals is not None and len( self.normals) and self.normalTransparency: nColours = [] Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) cam = GLU.gluUnProject((viewport[2] - viewport[0]) / 2, (viewport[3] - viewport[1]) / 2, 0.0, Mmat, Pmat, viewport) cam = np.array(cam, dtype=np.float32) diffs = self.vertices - cam # diffs *= -1 for di, diff in enumerate(diffs): nd = diff / np.linalg.norm(diff) dp = np.dot(nd, self.normals[di]) alpha = (dp - (-1)) / 2 * (1 - 0.15) + 0.15 if self.colours: nColours.append([ self.colours[di][0], self.colours[di][1], self.colours[di][2], alpha ]) else: nColours.append([ self.colour[0], self.colour[1], self.colour[2], alpha ]) self.colours = np.array(nColours, dtype=np.float32).reshape(-1, 4) GL.glPushMatrix() try: GL.glMultMatrixf(self.transform) drawPoints = DRAWOPT_POINTS & drawOpts if drawPoints: # actually draw the points if self.drawStyles is None: GL.glColor4f(*self.colour) self.drawPoints(np.arange(p0, p1, dtype=np.int32)) else: ds = self.drawStyles[p0:p1] which_empty = np.where(ds == 0)[0] which_pts = np.where(ds == 1)[0] which_crosses = np.where(ds == 2)[0] GL.glColor4f(1, 1, 0, 1) self.drawPoints(which_empty, p0) GL.glColor4f(*self.colour) self.drawPoints(which_pts, p0) self.drawCrosses(which_crosses, p0) GL.glDisableClientState(GL.GL_COLOR_ARRAY) #print self.selectedIndex if self.selectedIndex >= p0 and self.selectedIndex < p1: GL.glDisable(GL.GL_DEPTH_TEST) GL.glColor4f(1, 0, 0, 1) if self.drawStyles is None or self.drawStyles[ self.selectedIndex] != 2: self.drawPoints( np.arange(self.selectedIndex, self.selectedIndex + 1, dtype=np.int32)) else: self.drawCrosses( np.arange(self.selectedIndex, self.selectedIndex + 1, dtype=np.int32)) GL.glEnable(GL.GL_DEPTH_TEST) drawEdges = DRAWOPT_EDGES & drawOpts if self.edges is not None and drawEdges and not is_click: GL.glEnableClientState(GL.GL_VERTEX_ARRAY) GL.glVertexPointerf(self.vertices) GL.glColor4f(self.edgeColour[0], self.edgeColour[1], self.edgeColour[2], self.edgeColour[3]) GL.glLineWidth(1.0) GL.glDrawElementsui(GL.GL_LINES, self.edges) GL.glDisableClientState(GL.GL_VERTEX_ARRAY) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) drawLabels = DRAWOPT_POINT_LABELS & drawOpts if self.names is not None and not is_click and drawLabels: self.nameWidth = [ sum([ GLUT.glutBitmapWidth(self.font, ord(x)) for x in name ]) for name in self.names ] GL.glColor4f(*self.colour) Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) for name, v, w in zip(self.names, self.vertices, self.nameWidth)[p0:p1]: if bool(GL.glWindowPos2f): p = GLU.gluProject(v[0], v[1] + 5, v[2], Mmat, Pmat, viewport) GL.glWindowPos2f(p[0] - 0.5 * w, p[1]) else: GL.glRasterPos3f(v[0], v[1] + 5, v[2]) GLUT.glutBitmapString(self.font, name) except Exception, e: print 'ERROR', e, 'at line', sys.exc_info()[2].tb_lineno
def paintGL(self, p0=0, p1=None, drawOpts=DRAWOPT_DEFAULT): ''' :param drawOpts: OR combination of draw flags. default is :data:`UI.DRAWOPT_DEFAULT` ''' doingSelection = (p1 is not None) if doingSelection: return # TODO, selection not working because of using shaders if not self.d['draw'] or not self.d['visible']: return if p1 is None: p1 = len(self) if not self.GL_is_initialised: self.initializeGL() # could store a selected/non-selected colour, switch on selection change and avoid this if.. boneColour = COLOURS['Selected'] if self.d[K_SELECTED] else self.d[ K_BONE_COLOUR] # TODO: draw offset should be an option of THIS primitive, not a view based draw option? drawingOffset = DRAWOPT_OFFSET & drawOpts if drawingOffset: GL.glTranslate(self.offset[0], self.offset[1], self.offset[2]) GL.glEnable(GL.GL_BLEND) first_sel = self.numBones if self.transforms is not None and p0 < first_sel: GL.glUseProgram(self.colour_shader) b0, b1 = min(max(0, p0), first_sel), min(max(0, p1), first_sel) #GL.glUniform4fv(self.colour_shader_colours, 3, self.colours) # NOT WORKING GL.glUniform1iv( self.colour_shader_states, len(self.bone_colour_states), self.bone_colour_states ) # set the states so the shader can pick the correct colour per joint GL.glVertexAttrib4f(self.colour_shader_colour, *boneColour) GL.glVertexAttrib4f(self.colour_shader_alt_colour, *COLOURS['Hilighted']) GL.glEnableClientState(GL.GL_VERTEX_ARRAY) self.bvs.bind() GL.glVertexPointerf(self.bvs) GL.glEnableVertexAttribArray(self.colour_shader_bi) self.bvis.bind() GL.glVertexAttribIPointer(self.colour_shader_bi, 1, GL.GL_UNSIGNED_INT, 0, self.bvis) # write the bvis to bi if (DRAWOPT_BONES | DRAWOPT_JOINTS) & drawOpts: GL.glLineWidth(1) GL.glPointSize(5) for t0 in xrange(b0, b1, 128): # draw the bones in batches of 128 t1 = min(t0 + 128, b1) GL.glUniformMatrix4fv( self.colour_shader_myMat, t1 - t0, GL.GL_FALSE, self.transforms[t0:t1]) # put the transforms in myMat if DRAWOPT_BONES & drawOpts: GL.glDrawArrays(GL.GL_LINES, 2 * t0, 2 * (t1 - t0)) if DRAWOPT_JOINTS & drawOpts: GL.glDrawArrays(GL.GL_POINTS, 2 * t0, 2 * (t1 - t0)) self.bvis.unbind() GL.glDisableVertexAttribArray(self.colour_shader_bi) self.bvs.unbind() GL.glDisableClientState(GL.GL_VERTEX_ARRAY) if self.mvs and p1 > first_sel and DRAWOPT_MARKERS & drawOpts: assert self.numBones < 128, 'Only up to 128 bones are supported for now' GL.glUseProgram(self.colour_shader) m0, m1 = min(max(0, p0 - first_sel), self.numMarkers), min(max(0, p1 - first_sel), self.numMarkers) GL.glUniformMatrix4fv( self.colour_shader_myMat, len(self.transforms), GL.GL_FALSE, self.transforms) # put the transforms in myMat GL.glEnableClientState(GL.GL_VERTEX_ARRAY) self.mvs.bind() GL.glVertexPointerf(self.mvs) GL.glEnableVertexAttribArray(self.colour_shader_bi) self.mvis.bind() GL.glVertexAttribIPointer(self.colour_shader_bi, 1, GL.GL_UNSIGNED_INT, 0, self.mvis) # write the mvis to bi GL.glPointSize(5) GL.glVertexAttrib4f(self.colour_shader_colour, *self.d[K_MARKER_COLOUR]) # write the colour GL.glDrawArrays(GL.GL_POINTS, m0, m1 - m0) self.mvis.unbind() GL.glDisableVertexAttribArray(self.colour_shader_bi) self.mvs.unbind() GL.glDisableClientState(GL.GL_VERTEX_ARRAY) if p1 == len(self): if DRAWOPT_AXES & drawOpts: GL.glUseProgram(self.colour_shader) GL.glUniformMatrix4fv( self.shader_myMat, len(self.transforms), GL.GL_FALSE, self.transforms) # put the transforms in myMat GL.glEnableClientState(GL.GL_VERTEX_ARRAY) self.avs.bind() GL.glVertexPointerf(self.avs) GL.glEnableVertexAttribArray(self.colour_shader_bi) self.avis.bind() GL.glVertexAttribIPointer(self.colour_shader_bi, 1, GL.GL_UNSIGNED_INT, 0, self.avis) # write the avis to bi GL.glLineWidth(2) GL.glVertexAttrib4f(self.colour_shader_colour, 1, 0, 0, 1) # red GL.glVertexAttrib4f( self.colour_shader_alt_colour, 1, 0, 0, 1 ) # this doesn't seem clever. need to make the glUniform4fv work then make one call to set the 2 colours self.aris.bind() GL.glDrawElementsui(GL.GL_LINES, self.aris) # draw the lines self.aris.unbind() GL.glVertexAttrib4f(self.colour_shader_colour, 0, 1, 0, 1) # green GL.glVertexAttrib4f(self.colour_shader_alt_colour, 0, 1, 0, 1) self.agis.bind() GL.glDrawElementsui(GL.GL_LINES, self.agis) # draw the lines self.agis.unbind() GL.glVertexAttrib4f(self.colour_shader_colour, 0, 0, 1, 1) # blue GL.glVertexAttrib4f(self.colour_shader_alt_colour, 0, 0, 1, 1) self.abis.bind() GL.glDrawElementsui(GL.GL_LINES, self.abis) # draw the lines self.abis.unbind() self.avis.unbind() GL.glDisableVertexAttribArray(self.colour_shader_bi) self.avs.unbind() GL.glDisableClientState(GL.GL_VERTEX_ARRAY) GL.glUseProgram(self.shader) if self.image != self.bindImage: if self.bindImage is not None: self.deleteTexture(self.bindId) self.bindId, self.bindImage = long(0), None if self.image is not None: global win self.bindId = self.view.bindTexture(self.image) self.bindImage = self.image if self.bindImage is not None: GL.glEnable(GL.GL_TEXTURE_2D) GL.glBindTexture(GL.GL_TEXTURE_2D, self.bindId) GL.glEnable(GL.GL_CULL_FACE) GL.glCullFace(GL.GL_BACK) GL.glFrontFace(GL.GL_CCW) GL.glEnable(GL.GL_LIGHTING) GL.glEnable(GL.GL_LIGHT0) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) lightDir = -Pmat[:3, 2] # the direction the camera is looking GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightDir) if self.d[K_COLOUR]: GL.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, self.d[K_COLOUR]) if self.vs is not None: GL.glEnableClientState(GL.GL_VERTEX_ARRAY) self.vs.bind() GL.glVertexPointerf(self.vs) if self.vts is not None: GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY) self.vts.bind() GL.glTexCoordPointerf(self.vts) if self.vns is not None: GL.glEnableClientState(GL.GL_NORMAL_ARRAY) self.vns.bind() GL.glNormalPointerf(self.vns) if self.tris is not None: GL.glDrawElementsui(GL.GL_TRIANGLES, self.tris) # static geom if self.transformData is not None and self.transforms is not None: GL.glUniformMatrix4fv( self.shader_myMat, len(self.transforms), GL.GL_FALSE, self.transforms) # put the transforms in myMat GL.glEnableVertexAttribArray(self.shader_bi) self.vtis.bind() GL.glVertexAttribIPointer(self.shader_bi, 1, GL.GL_UNSIGNED_INT, 0, self.vtis) # write the vtis to bi if DRAWOPT_GEOMS & drawOpts: self.tis.bind() GL.glDrawElementsui(GL.GL_TRIANGLES, self.tis) # draw the triangles self.tis.unbind() self.vtis.unbind() GL.glDisableVertexAttribArray(self.shader_bi) if self.vs is not None: self.vs.unbind() GL.glDisableClientState(GL.GL_VERTEX_ARRAY) if self.vts is not None: self.vts.unbind() GL.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY) if self.vns is not None: self.vns.unbind() GL.glDisableClientState(GL.GL_NORMAL_ARRAY) GL.glDisable(GL.GL_LIGHTING) GL.glDisable(GL.GL_TEXTURE_2D) GL.glDisable(GL.GL_BLEND) GL.glUseProgram(0) if self.d[ K_NAME] is not None and self.transforms is not None and DRAWOPT_LABELS & drawOpts: try: GL.glColor4f(*boneColour) phi = np.max(self.transforms[:, 3, :3], axis=0) plo = np.min(self.transforms[:, 3, :3], axis=0) if bool(GL.glWindowPos2f): Mmat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) Pmat = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX) viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) p = GLU.gluProject((phi[0] + plo[0]) * 0.5, phi[1] + 300.0, (phi[2] + plo[2]) * 0.5, Mmat, Pmat, viewport) if p[2] > 0 and p[2] < 1: # near/far clipping of text # TODO, now this won't change if name changes... if self.nameWidth is None: self.nameWidth = sum([ GLUT.glutBitmapWidth(self.font, ord(x)) for x in self.d[K_NAME] ]) GL.glWindowPos2f(p[0] - 0.5 * self.nameWidth, p[1]) GLUT.glutBitmapString(self.font, self.d[K_NAME]) else: GL.glRasterPos3f((phi[0] + plo[0]) * 0.5, phi[1] + 300.0, (phi[2] + plo[2]) * 0.5) GLUT.glutBitmapString(self.font, self.d[K_NAME]) except ValueError: pass # projection failed if DRAWOPT_OFFSET & drawOpts: GL.glTranslate(-self.offset[0], -self.offset[1], -self.offset[2])