def draw(self): planes = self.planes assert len(planes) <= len(GL_CLIP_PLANE_table), \ "no more than %d clipping planes are permitted" % \ len(GL_CLIP_PLANE_table) # even if your OpenGL driver supports more -- no sense writing an expr that not everyone can draw! # WARNING: this ignores the issue of nested Clipped constructs! # In fact, it assumes nothing in thing or above self uses any clipping planes. # (Not merely "assumes no more than 6 in all", because we hardcode which specific planes to use!) # Worse, we don't even detect the error. Fixing the behavior is just as easy # (let graphical dynenv (self.env) know which planes are still available to any drawing-kid), so do that instead. ##e # Note that we might need to work inside a display list, and therefore we'd need to get the "next plane to use" # from an env which stays fixed (or from an env var which is changedtracked), not just from each draw call's caller # (i.e. a glpane attr). # enable the planes for i, plane in zip(range(len(planes)), planes): assert len(plane) == 4 glEnable( GL_CLIP_PLANE_table[i] ) glClipPlane( GL_CLIP_PLANE_table[i], plane) # draw thing self.drawkid( self.thing) # disable the planes for i in range(len(planes)): glDisable( GL_CLIP_PLANE_table[i] ) return
def fog_on_off(self): if self.has_gl : if not self.fogmode: self.has_fog=1 glEnable(GL_FOG) glFogf(GL_FOG_MODE, GL_LINEAR) glHint(GL_FOG_HINT, GL_NICEST) """ glFogf(GL_FOG_DENSITY,0.2) c=self.camera.GetDistance() s=self.slab z=self.zpos glFogf(GL_FOG_START, c-z-s/2.) glFogf(GL_FOG_END, 2000) self.renwin.Render() """ self.update_fog_dist() self.update_fog_density() self.itf.dist.configure(state=tk.NORMAL) self.itf.density.configure(state=tk.NORMAL) self.fogmode=1 else: glDisable(GL_FOG) self.renwin.Render() self.itf.dist.configure(state=tk.DISABLED) self.itf.density.configure(state=tk.DISABLED) self.fogmode=0
def draw_vertices(self): # Draw all the vbo defined in set_atoms if self.transparent: glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glDepthMask(GL_FALSE) if self.wireframe: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) glEnableClientState(GL_VERTEX_ARRAY) self._vbo_v.bind_vertexes(3, GL_FLOAT) glEnableClientState(GL_NORMAL_ARRAY) self._vbo_n.bind_normals(GL_FLOAT) glEnableClientState(GL_COLOR_ARRAY) self._vbo_c.bind_colors(4, GL_UNSIGNED_BYTE) glDrawArrays(GL_TRIANGLES, 0, self._n_triangles) self._vbo_v.unbind() self._vbo_n.unbind() self._vbo_c.unbind() if self.transparent: glDisable(GL_BLEND) #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glDepthMask(GL_TRUE) if self.wireframe: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
def drawline_worker(params): """ Draw a line. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) """ (endpt1, endpt2, dashEnabled, stipleFactor, width, isSmooth) = params ###glDisable(GL_LIGHTING) ###glColor3fv(color) if dashEnabled: glLineStipple(stipleFactor, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) if isSmooth: glEnable(GL_LINE_SMOOTH) glBegin(GL_LINES) glVertex(endpt1[0], endpt1[1], endpt1[2]) glVertex(endpt2[0], endpt2[1], endpt2[2]) glEnd() if isSmooth: glDisable(GL_LINE_SMOOTH) if width != 1: glLineWidth(1.0) # restore default state if dashEnabled: glDisable(GL_LINE_STIPPLE) ###glEnable(GL_LIGHTING) return
def initialize(self): glutPositionWindow(0, 600) GLRealtimeProgram.initialize(self) colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (0, 1, 1), (1, 0, 1)] for (i, cloud) in enumerate(self.clouds): point_list = glGenLists(i + 1) self.point_lists.append(point_list) # compile the point cloud glNewList(point_list, GL_COMPILE) glDisable(GL_LIGHTING) glBegin(GL_POINTS) for point in cloud: if len(point) == 2: xyz = point[0] rgb = point[1] else: xyz = point[:3] if len(point) == 4: rgb = point[3] elif len(point) > 4: rgb = point[3:6] else: rgb = None if rgb is not None: glColor3f(*map(lambda x: x / 255.0, rgb)) else: glColor3f(*colors[i % len(colors)]) glVertex3f(*xyz[:3]) glEnd() glEndList() logging.debug("compiled {} points for cloud {}".format(len(cloud), i))
def render(self): self.clock.record_frame_time() if self.is_recording and not self.timer.is_snoozed: self.frame_index += 1 frame_name = "Frame_{0:05d}.jpg".format(self.frame_index) self.save_screenshot(frame_name) self.timer.snooze() glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) if camera.is_rotating: camera.rotate_z(0.2) camera.look() self.draw_detector() glEnable(GL_DEPTH_TEST) glEnable(GL_LINE_SMOOTH) glShadeModel(GL_FLAT) glEnable(GL_LIGHTING) for obj in self.shaded_objects: obj.draw(self.clock.time, self.spectrum) glDisable(GL_LIGHTING) for obj in self.objects: obj.draw(self.clock.time) self.draw_gui() glutSwapBuffers()
def do_configure_event(self, event): ClientWindow.do_configure_event(self, event) drawable = self.glarea.get_gl_drawable() context = self.glarea.get_gl_context() self.yuv420_shader = None # Re-create textures self.current_mode = GLClientWindow.MODE_UNINITIALIZED if not drawable.gl_begin(context): raise Exception("** Cannot create OpenGL rendering context!") w, h = self.get_size() log("Configure widget size: %d x %d" % (w, h)) glViewport(0, 0, w, h) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, w, h, 0.0, -1.0, 1.0) glMatrixMode(GL_MODELVIEW) glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_TEXTURE_COORD_ARRAY) glDisable(GL_FRAGMENT_PROGRAM_ARB) if self.textures is None: self.textures = glGenTextures(3) drawable.gl_end()
def wrapper(self, *args, **kvargs): glEnable(GL_TEXTURE_2D) try: return func(self, *args, **kvargs) finally: glDisable(GL_TEXTURE_2D)
def drawRotateSign(color, pos1, pos2, radius, rotation=0.0): """Rotate sign on top of the caps of the cylinder """ glPushMatrix() glColor3fv(color) vec = pos2 - pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518 glScale(radius, radius, Numeric.dot(vec, vec)**.5) glLineWidth(2.0) glDisable(GL_LIGHTING) glCallList(drawing_globals.rotSignList) glEnable(GL_LIGHTING) glLineWidth(1.0) glPopMatrix() return
def drawFilledCircle(color, center, radius, normal): """ Scale, rotate/translate the unit circle properly. Added a filled circle variant, piotr 080405 """ glMatrixMode(GL_MODELVIEW) glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) rQ = Q(V(0, 0, 1), normal) rotAngle = rQ.angle * 180.0 / pi #This may cause problems as proved before in Linear motor display. #rotation around (0, 0, 0) #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005: # rQ.x = 1.0 glRotatef(rotAngle, rQ.x, rQ.y, rQ.z) glScalef(radius, radius, 1.0) glCallList(drawing_globals.filledCircleList) glEnable(GL_LIGHTING) glPopMatrix() return
def drawFullWindow(vtColors): """ Draw gradient background color. <vtColors> is a 4 element list specifying colors for the left-down, right-down, right-up, left-up window corners. To draw the full window, the modelview and projection should be set in identity. """ from utilities.constants import GL_FAR_Z glDisable(GL_LIGHTING) glBegin(GL_QUADS) glColor3fv(vtColors[0]) glVertex3f(-1, -1, GL_FAR_Z) glColor3fv(vtColors[1]) glVertex3f(1, -1, GL_FAR_Z) glColor3fv(vtColors[2]) glVertex3f(1, 1, GL_FAR_Z) glColor3fv(vtColors[3]) glVertex3f(-1, 1, GL_FAR_Z) glEnd() glEnable(GL_LIGHTING) return
def disable_fog(self): if self.has_fog: glDisable(GL_FOG) self.renwin.Render() self.has_fog = 0 else: self.make_fog()
def fog_on_off(self): if self.has_gl: if not self.fogmode: self.has_fog = 1 glEnable(GL_FOG) glFogf(GL_FOG_MODE, GL_LINEAR) glHint(GL_FOG_HINT, GL_NICEST) """ glFogf(GL_FOG_DENSITY,0.2) c=self.camera.GetDistance() s=self.slab z=self.zpos glFogf(GL_FOG_START, c-z-s/2.) glFogf(GL_FOG_END, 2000) self.renwin.Render() """ self.update_fog_dist() self.update_fog_density() self.itf.dist.configure(state=tk.NORMAL) self.itf.density.configure(state=tk.NORMAL) self.fogmode = 1 else: glDisable(GL_FOG) self.renwin.Render() self.itf.dist.configure(state=tk.DISABLED) self.itf.density.configure(state=tk.DISABLED) self.fogmode = 0
def disable_fog(self): if self.has_fog: glDisable(GL_FOG) self.renwin.Render() self.has_fog=0 else : self.make_fog()
def drawPoint(color, point, pointSize = 3.0, isRound = True): """ Draw a point using GL_POINTS. @param point: The x,y,z coordinate array/ vector of the point @type point: A or V @param pointSize: The point size to be used by glPointSize @type pointSize: float @param isRound: If True, the point will be drawn round otherwise square @type isRound: boolean """ glDisable(GL_LIGHTING) glColor3fv(color) glPointSize(float(pointSize)) if isRound: glEnable(GL_POINT_SMOOTH) glBegin(GL_POINTS) glVertex3fv(point) glEnd() if isRound: glDisable(GL_POINT_SMOOTH) glEnable(GL_LIGHTING) if pointSize != 1.0: glPointSize(1.0) return
def drawbrick(color, center, axis, l, h, w, opacity = 1.0): if len(color) == 3: color = (color[0], color[1], color[2], opacity) if opacity != 1.0: glDepthMask(GL_FALSE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) apply_material(color) glPushMatrix() glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(h, w, l) #bruce 060302 revised the contents of solidCubeList while fixing bug 1595 glCallList(drawing_globals.solidCubeList) if opacity != 1.0: glDisable(GL_BLEND) glDepthMask(GL_TRUE) glPopMatrix() return
def drawPoint(color, point, pointSize=3.0, isRound=True): """ Draw a point using GL_POINTS. @param point: The x,y,z coordinate array/ vector of the point @type point: A or V @param pointSize: The point size to be used by glPointSize @type pointSize: float @param isRound: If True, the point will be drawn round otherwise square @type isRound: boolean """ glDisable(GL_LIGHTING) glColor3fv(color) glPointSize(float(pointSize)) if isRound: glEnable(GL_POINT_SMOOTH) glBegin(GL_POINTS) glVertex3fv(point) glEnd() if isRound: glDisable(GL_POINT_SMOOTH) glEnable(GL_LIGHTING) if pointSize != 1.0: glPointSize(1.0) return
def draw(self): """ Draws each frame. """ print("draw()") # DRAW STUFF HERE glDisable(GL_TEXTURE_RECTANGLE_ARB) glColor4f(1.0, 0.8, 0.2, 1.0) glPushMatrix() glScale(0.5, 0.5, 1.0) draw_square() glPopMatrix() glColor4f(1.0, 1.0, 0.0, 0.8) num = 64 for i in range(num): x = (i / float(num)) * 4 - 2 draw_line(float(x), -2.0, float(x), 2.0) draw_line(-2.0, float(x), 2.0, float(x)) if self.texture_id is not None: glColor4f(1.0, 1.0, 1.0, 1.0) glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.texture_id) glPushMatrix() glScale(0.4, 0.3, 1.0) draw_textured_square(320, 240) glPopMatrix() else: print "No texture to draw"
def drawrectangle(pt1, pt2, rt, up, color): """ Draws a (hollow) rectangle outline of the given I{color}. @param pt1: First corner of the rectangle. @type pt1: Point @param pt1: Opposite corner of the rectangle. @type pt1: Point @param rt: Right vector of the glpane. @type rt: Unit vector @param up: Right vector of the glpane. @type up: Unit vector @param color: Color @type color: color """ glColor3f(color[0], color[1], color[2]) glDisable(GL_LIGHTING) c2 = pt1 + rt * Numeric.dot(rt, pt2 - pt1) c3 = pt1 + up * Numeric.dot(up, pt2 - pt1) glBegin(GL_LINE_LOOP) glVertex(pt1[0], pt1[1], pt1[2]) glVertex(c2[0], c2[1], c2[2]) glVertex(pt2[0], pt2[1], pt2[2]) glVertex(c3[0], c3[1], c3[2]) glEnd() glEnable(GL_LIGHTING)
def drawwiresphere_worker(params): """ Draw a wireframe sphere. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) """ (color, pos, radius, detailLevel) = params ## assert detailLevel == 1 # true, but leave out for speed from utilities.debug_prefs import debug_pref, Choice_boolean_True #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it! newway = debug_pref("new wirespheres?", Choice_boolean_True) oldway = not newway # These objects want a constant line color even if they are selected or # highlighted. glColor3fv(color) glDisable(GL_LIGHTING) if oldway: glPolygonMode(GL_FRONT, GL_LINE) glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) glScale(radius, radius, radius) if oldway: glCallList(drawing_globals.sphereList[detailLevel]) else: glCallList(drawing_globals.wiresphere1list) glEnable(GL_LIGHTING) glPopMatrix() if oldway: glPolygonMode(GL_FRONT, GL_FILL) return
def drawbrick(color, center, axis, l, h, w, opacity=1.0): if len(color) == 3: color = (color[0], color[1], color[2], opacity) if opacity != 1.0: glDepthMask(GL_FALSE) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) apply_material(color) glPushMatrix() glTranslatef(center[0], center[1], center[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2]) * 180.0 / pi if (axis[2] * axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glScale(h, w, l) #bruce 060302 revised the contents of solidCubeList while fixing bug 1595 glCallList(drawing_globals.solidCubeList) if opacity != 1.0: glDisable(GL_BLEND) glDepthMask(GL_TRUE) glPopMatrix() return
def render(self): #初始化投影矩阵 self.init_view() #启动光照 glEnable(GL_LIGHTING) #清空颜色缓存与深度缓存 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #设置模型视图矩阵,这节课先用单位矩阵就行了。 glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glMultMatrixf(self.interaction.trackball.matrix) # 存储ModelView矩阵与其逆矩阵之后做坐标系转换用 currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX)) self.modelView = numpy.transpose(currentModelView) self.inverseModelView = inv(numpy.transpose(currentModelView)) #渲染场景 self.scene.render() #每次渲染后复位光照状态 glDisable(GL_LIGHTING) glCallList(G_OBJ_PLANE) glPopMatrix() #把数据刷新到显存上 glFlush()
def drawCubeCell(color): sp0 = drawing_globals.sp0 sp4 = drawing_globals.sp4 vs = [[sp0, sp0, sp0], [sp4, sp0, sp0], [sp4, sp4, sp0], [sp0, sp4, sp0], [sp0, sp0, sp4], [sp4, sp0, sp4], [sp4, sp4, sp4], [sp0, sp4, sp4]] glDisable(GL_LIGHTING) glColor3fv(color) glBegin(GL_LINE_LOOP) for ii in range(4): glVertex3fv(vs[ii]) glEnd() glBegin(GL_LINE_LOOP) for ii in range(4, 8): glVertex3fv(vs[ii]) glEnd() glBegin(GL_LINES) for ii in range(4): glVertex3fv(vs[ii]) glVertex3fv(vs[ii + 4]) glEnd() glEnable(GL_LIGHTING) return
def InitGL(self, Width, Height): self.view_port_xr = 1 self.view_port_yr = 1 self.original_x = Width self.original_y = Height glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, Width, 0, Height, -1, 1) glScalef(1, -1, 1) glTranslatef(0, -Height, 0) glMatrixMode(GL_MODELVIEW) glDisable(GL_DEPTH_TEST) # Disables Depth Testing glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading # Anti-aliasing/prettyness stuff glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glHint(GL_POINT_SMOOTH_HINT, GL_NICEST) glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) glEnable(GL_LINE_SMOOTH) glEnable(GL_POINT_SMOOTH) glEnable(GL_POLYGON_SMOOTH) glClearColor(background_color()[0], background_color()[1], background_color()[2], 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
def draw_filled_rect(origin, dx, dy, color): ## print 'draw_filled_rect',(origin, dx, dy, color) #####@@@@@ glDisable( GL_LIGHTING ) # this allows the specified color to work. Otherwise it doesn't work (I always get dark blue). Why??? # guess: if i want lighting, i have to specify a materialcolor, not just a regular color. (and vertex normals) try: len(color) except: print "following exception in len(color) for color = %r" % ( color, ) # 061212 -- why didn't caller's fix_color catch it? ##k raise if len(color) == 4: glColor4fv(color) if 0 and color[3] != 1.0: print "color has alpha", color ####@@@@ else: glColor3fv(color) ## glRectfv(origin, origin + dx + dy) # won't work for most coords! also, ignores Z. color still not working. glBegin(GL_QUADS) glVertex3fv(origin) # glColor3fv(white)# glVertex3fv(origin + dx) # glColor3fv(white) # hack, see if works - yes! # glColor3fv(color)# glVertex3fv(origin + dx + dy) # glColor3fv(white)# glVertex3fv(origin + dy) glEnd() glEnable( GL_LIGHTING ) # should be outside of glEnd! when inside, i got infloop! (not sure that was why; quit/reran after that)
def draw_textured_rect_subtriangle( origin, dx, dy, tex_origin, tex_dx, tex_dy, points ): # 070404 modified from draw_textured_rect """ Like draw_textured_rect, but draw only the sub-triangle of the same rect (textured in the same way), where the subtriangle has relative 2d vertices as specified inside that rect (treating its own coords as each in [0.0, 1.0]). WARNING: depending on the glEnables set up by the caller, the sub-triangle coords might need to be in CCW winding order for the triangle to be visible from the front. """ # e could easily generalize API to polygon, and this implem to convex polygon, if desired ##e WARNING: this function's name and api are likely to be revised; # or we might just replace the whole scheme, using things like Textured(Triangle(...),...) instead, # perhaps implemented by telling OpenGL how to compute the texture coords in a wrapper, then just drawing the triangle. assert len(points) == 3 # and each point should be a V of length 2, or a 2-tuple, with elements convertible to floats -- this is assumed below glEnable(GL_TEXTURE_2D) glBegin(GL_TRIANGLES) for px, py in points: px = float(px) py = float(py) glTexCoord2fv((tex_origin + px * tex_dx + py * tex_dy).tolist()) # glVertex3fv(origin + px * dx + py * dy) glEnd() glDisable(GL_TEXTURE_2D)
def draw_colour_legend(self): menubar_height = self.logo.size[1] + 4 width = glutGet(GLUT_WINDOW_WIDTH) height = glutGet(GLUT_WINDOW_HEIGHT) # Colour legend left_x = width - 20 right_x = width - 10 min_y = menubar_height + 5 max_y = height - 20 time_step_size = math.ceil(self.max_hit_time / 20 / 50) * 50 hit_times = list(range(int(self.min_hit_time), int(self.max_hit_time), int(time_step_size))) if len(hit_times) > 1: segment_height = int((max_y - min_y) / len(hit_times)) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glDisable(GL_LIGHTING) glBegin(GL_QUADS) for hit_time in hit_times: segment_nr = hit_times.index(hit_time) glColor3f(*self.spectrum(hit_time)) glVertex2f(left_x, max_y - segment_height * segment_nr) glVertex2f(right_x, max_y - segment_height * segment_nr) glColor3f(*self.spectrum(hit_time + time_step_size)) glVertex2f(left_x, max_y - segment_height * (segment_nr + 1)) glVertex2f(right_x, max_y - segment_height * (segment_nr + 1)) glEnd() # Colour legend labels self.colourist.now_text() for hit_time in hit_times: segment_nr = hit_times.index(hit_time) draw_text_2d("{0:>5}ns".format(hit_time), width - 80, (height - max_y) + segment_height * segment_nr)
def drawcylinder_wireframe(color, end1, end2, radius): #bruce 060608 """ Draw a wireframe cylinder (not too pretty, definitely could look nicer, but it works.) """ # display polys as their edges (see drawer.py's drawwirecube or Jig.draw for # related code) (probably we should instead create a suitable lines display # list, or even use a wire-frame-like texture so various lengths work well) glPolygonMode(GL_FRONT, GL_LINE) glPolygonMode(GL_BACK, GL_LINE) glDisable(GL_LIGHTING) # This makes motors look too busy, but without it, they look too weird # (which seems worse.) glDisable(GL_CULL_FACE) try: ##k Not sure if this color will end up controlling the edge color; we ## hope it will. drawcylinder(color, end1, end2, radius) except: debug.print_compact_traceback("bug, ignored: ") # The following assumes that we are never called as part of a jig's drawing # method, or it will mess up drawing of the rest of the jig if it's # disabled. glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glPolygonMode(GL_FRONT, GL_FILL) glPolygonMode(GL_BACK, GL_FILL) # could probably use GL_FRONT_AND_BACK return
def render(self): #init shadow matrix self.init_view() #open light glEnable(GL_LIGHTING) #clear color and depth caches glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) #set model view matrix(danwei matrix is ok) #set trackball's rotate matrix as Modelview glMatrixMode(GL_MODELVIEW) glPushMatrix() #replace now-matrix with hengdeng matrix glLoadIdentity() glMultMatrixf(self.interaction.trackball.matrix) #save Modelview matrix, later change system with anti-matrix currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX)) self.modelView = numpy.transpose(currentModelView) self.inverseModelView = inv(numpy.transpose(currentModelView)) #rend the scene self.scene.render() #after each shadow , huifu light state glDisable(GL_LIGHTING) glPopMatrix() glFlush()
def drawArrowHead(color, basePoint, drawingScale, unitBaseVector, unitHeightVector): arrowBase = drawingScale * 0.08 arrowHeight = drawingScale * 0.12 glDisable(GL_LIGHTING) glPushMatrix() glTranslatef(basePoint[0],basePoint[1],basePoint[2]) point1 = V(0, 0, 0) point1 = point1 + unitHeightVector * arrowHeight point2 = unitBaseVector * arrowBase point3 = - unitBaseVector * arrowBase #Draw the arrowheads as filled triangles glColor3fv(color) glBegin(GL_POLYGON) glVertex3fv(point1) glVertex3fv(point2) glVertex3fv(point3) glEnd() glPopMatrix() glEnable(GL_LIGHTING)
def draw(self, camera_matrix: numpy.ndarray, camera_position: PointCoordinatesAny = None): """ Draw the selection box :param camera_matrix: 4x4 transformation matrix for the camera :param camera_position: The position of the camera. Used to flip draw direction if camera inside box. :return: """ self._setup() if self._rebuild: self._create_geometry() transformation_matrix = numpy.matmul(camera_matrix, self.transformation_matrix) # draw the lines around the boxes self.draw_start = 0 self.draw_count = 36 glDisable(GL_DEPTH_TEST) self._draw_mode = GL_LINE_STRIP super()._draw(transformation_matrix) glEnable(GL_DEPTH_TEST) if camera_position is not None and camera_position in self: glCullFace(GL_FRONT) else: glCullFace(GL_BACK) self._draw_mode = GL_TRIANGLES self.draw_start = 36 # 6 faces, 9 quads/face, 2 triangles/quad, 3 verts/triangle self.draw_count = 324 super()._draw(transformation_matrix) glCullFace(GL_BACK)
def draw_conf_corner_bg_image(self, pos = None): #bruce 070626 (pos argument is just for development & debugging) """ Redraw the previously grabbed conf_corner_bg_image, in the same place from which it was grabbed, or in the specified place (lower left corner of pos, in OpenGL window coords). Note: this modifies the OpenGL raster position. """ if not self._conf_corner_bg_image_data: print "self._conf_corner_bg_image_data not yet assigned" else: subwidth, subheight, width, height, gl_format, gl_type, image = self._conf_corner_bg_image_data if width != self.width or height != self.height: # I don't know if this can ever happen; if it can, caller might need # to detect this itself and do a full redraw. # (Or we might make this method return a boolean to indicate it.) print "can't draw self._conf_corner_bg_image_data -- glpane got resized" ### else: if pos is None: pos = (width - subwidth, height - subheight) x, y = pos self._set_raster_pos(x, y) glDisable(GL_DEPTH_TEST) # otherwise it can be obscured by prior drawing into depth buffer # Note: doing more disables would speed up glDrawPixels, # but that doesn't matter unless we do it many times per frame. glDrawPixels(subwidth, subheight, gl_format, gl_type, image) glEnable(GL_DEPTH_TEST) pass return
def drawCubeCell(color): sp0 = drawing_globals.sp0 sp4 = drawing_globals.sp4 vs = [[sp0, sp0, sp0], [sp4, sp0, sp0], [sp4, sp4, sp0], [sp0, sp4, sp0], [sp0, sp0, sp4], [sp4, sp0, sp4], [sp4, sp4, sp4], [sp0, sp4, sp4]] glDisable(GL_LIGHTING) glColor3fv(color) glBegin(GL_LINE_LOOP) for ii in range(4): glVertex3fv(vs[ii]) glEnd() glBegin(GL_LINE_LOOP) for ii in range(4, 8): glVertex3fv(vs[ii]) glEnd() glBegin(GL_LINES) for ii in range(4): glVertex3fv(vs[ii]) glVertex3fv(vs[ii+4]) glEnd() glEnable(GL_LIGHTING) return
def initializeGL(self): ''' Initialize GL ''' self.fieldtemp = [ 1.0, "GL_NEAREST", "GL_NEAREST", "GL_NEAREST_MIPMAP_NEAREST", "On" ] try: js = jsonload(path.join(SAVE_DIR, "gfx_settings.rgs")) self.fieldtemp[0] = loadFloat('gfx.anifilt', js.get('anifilt')) self.fieldtemp[1] = loadString('gfx.minfilter', js.get('minfilter')) self.fieldtemp[2] = loadString('gfx.magfilter', js.get('magfilter')) self.fieldtemp[3] = loadString('gfx.mipminfilter', js.get('mipminfilter')) self.fieldtemp[4] = loadString('gfx.FSAA', js.get('FSAA')) except: #print("no settings detected") pass #mipmap support and NPOT texture support block if not hasGLExtension("GL_ARB_framebuffer_object"): #print("GL_ARB_framebuffer_object not supported, switching to GL_GENERATE_MIPMAP") self.npot = 2 version = glGetString(GL_VERSION) if int(version[0]) == 1 and int( version[2]) < 4: #no opengl 1.4 support #print("GL_GENERATE_MIPMAP not supported, not using mipmapping") self.npot = 1 if not hasGLExtension("GL_ARB_texture_rectangle"): #print("GL_TEXTURE_RECTANGLE_ARB not supported, switching to GL_TEXTURE_2D") self.texext = GL_TEXTURE_2D self.npot = 0 #assorted settings block if hasGLExtension("GL_EXT_texture_filter_anisotropic" ) and self.fieldtemp[0] > 1.0: self.anifilt = self.fieldtemp[0] #print("using " + str(self.fieldtemp[0]) + "x anisotropic texture filtering. max: " + str(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT))) self.minfilter = self.interpretString(self.fieldtemp[1]) self.magfilter = self.interpretString(self.fieldtemp[2]) self.mipminfilter = self.interpretString(self.fieldtemp[3]) if self.mipminfilter == "Off": self.mipminfilter = -1 if self.format().sampleBuffers() and self.fieldtemp[4] == "On": #print("enabling " + str(self.format().samples()) + "x FSAA") glEnable(GL_MULTISAMPLE) else: pass #print("FSAA not supported and/or disabled") glEnable(self.texext) glEnable(GL_BLEND) glDisable(GL_DEPTH_TEST) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glViewport(0, 0, self.width(), self.height()) glClearColor(0.0, 0.0, 0.0, 0.0)
def compile_total_list(self): if self.total_list is not None: glNewList(self.total_list, GL_COMPILE) # reset a few things glDisable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() # change the modelview to camera coordinates viewport = glGetIntegerv(GL_VIEWPORT) width = viewport[2] - viewport[0] height = viewport[3] - viewport[1] if width > height: w = float(width) / float(height) h = 1.0 else: w = 1.0 h = float(height) / float(width) glScalef(2 / w, 2 / h, 1.0) glCallList(self.draw_list) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEndList()
def leftDown(self, event): """ Compute the rubber band window starting point, which lies on the near clipping plane, projecting into the same point that current cursor points at on the screen plane. """ self.pWxy = (event.pos().x(), self.glpane.height - event.pos().y()) p1 = A(gluUnProject(self.pWxy[0], self.pWxy[1], 0.005)) self.pStart = p1 self.pPrev = p1 self.firstDraw = True self.command.glStatesChanged = True # this warns our exit code to undo the following OpenGL state changes: self.glpane.redrawGL = False glDisable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) rbwcolor = self.command.rbwcolor glColor3d(rbwcolor[0], rbwcolor[1], rbwcolor[2]) glEnable(GL_COLOR_LOGIC_OP) glLogicOp(GL_XOR) return
def _do_paint_rgb24(self, img_data, x, y, w, h, rowstride, options, callbacks): log("do_paint_rgb24(%s bytes, %s, %s, %s, %s, %s, %s, %s)", len(img_data), x, y, w, h, rowstride, options, callbacks) ww, wh = self.size if x+w>ww or y+h>wh: log("do_paint_rgb24: ignoring paint which would overflow the backing area") return drawable = self.gl_init() if not drawable: log("do_paint_rgb24: cannot paint yet..") return try: #cleanup if we were doing yuv previously: if self.pixel_format!=GLPixmapBacking.RGB24: self.remove_shader() self.pixel_format = GLPixmapBacking.RGB24 glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[0]) glPixelStorei(GL_UNPACK_ROW_LENGTH, rowstride/3) for texture in (GL_TEXTURE1, GL_TEXTURE2): glActiveTexture(texture) glDisable(GL_TEXTURE_RECTANGLE_ARB) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, img_data) glBegin(GL_QUADS) for rx,ry in ((x, y), (x, y+h), (x+w, y+h), (x+w, y)): glTexCoord2i(rx, ry) glVertex2i(rx, ry) glEnd() finally: self.gl_end(drawable)
def draw_lines(self): "draw our line segments, using our current style attrs [which are partly nim]" # find variables which determine our GL state color = self.fix_color(self.linecolor) dashEnabled = self.dashed width = self.linewidth # set temporary GL state (code copied from drawer.drawline) glDisable(GL_LIGHTING) glColor3fv(color) if dashEnabled: glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) # draw the lines if self._closed_state: glBegin(GL_LINE_LOOP) else: glBegin(GL_LINE_STRIP) for pos in self.points: glVertex3fv( pos ) # [note from old code: could be pos + origin if that can matter] glEnd() # restore default GL state [some of this might be moved up to callers] if width != 1: glLineWidth(1.0) if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def render(self) -> None: """Render chamber to canvas.""" if not self.init(): return glDisable(GL_LINE_SMOOTH) proj = self.parent.projection_matrix modelview = self.parent.modelview_matrix glUseProgram(self.parent.shaders['default']) glUniformMatrix4fv(0, 1, GL_FALSE, glm.value_ptr(proj)) glUniformMatrix4fv(1, 1, GL_FALSE, glm.value_ptr(modelview)) if self._grid_shown: self._render_gridlines() if self._axes_shown: self._render_axes() if self._bbox_shown: self._render_bounding_box() glBindVertexArray(0) glUseProgram(0) glEnable(GL_LINE_SMOOTH)
def draw_lines(self): """ draw our line segments, using our current style attrs [which are partly nim] """ # find variables which determine our GL state color = self.fix_color(self.linecolor) dashEnabled = self.dashed width = self.linewidth # set temporary GL state (code copied from drawer.drawline) glDisable(GL_LIGHTING) glColor3fv(color) if dashEnabled: glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) # draw the lines if self._closed_state: glBegin(GL_LINE_LOOP) else: glBegin(GL_LINE_STRIP) for pos in self.points: glVertex3fv(pos) # [note from old code: could be pos + origin if that can matter] glEnd() # restore default GL state [some of this might be moved up to callers] if width != 1: glLineWidth(1.0) if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def draw_filled_rect(origin, dx, dy, color): ## print 'draw_filled_rect',(origin, dx, dy, color) #####@@@@@ glDisable(GL_LIGHTING) # this allows the specified color to work. Otherwise it doesn't work (I always get dark blue). Why??? # guess: if i want lighting, i have to specify a materialcolor, not just a regular color. (and vertex normals) try: len(color) except: print "following exception in len(color) for color = %r" % (color,) # 061212 -- why didn't caller's fix_color catch it? ##k raise if len(color) == 4: glColor4fv(color) if 0 and color[3] != 1.0: print "color has alpha",color ####@@@@ else: glColor3fv(color) ## glRectfv(origin, origin + dx + dy) # won't work for most coords! also, ignores Z. color still not working. glBegin(GL_QUADS) glVertex3fv(origin) #glColor3fv(white)# glVertex3fv(origin + dx) # glColor3fv(white) # hack, see if works - yes! #glColor3fv(color)# glVertex3fv(origin + dx + dy) #glColor3fv(white)# glVertex3fv(origin + dy) glEnd() glEnable(GL_LIGHTING) # should be outside of glEnd! when inside, i got infloop! (not sure that was why; quit/reran after that)
def render(self): """ The render pass for the scene """ self.init_view() # Enable lighting and color glEnable(GL_LIGHTING) glClearColor(0.4, 0.4, 0.4, 0.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Load the modelview matrix from the current state of the trackball glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() loc = self.interaction.translation glTranslated(-loc[0], -loc[1], -loc[2]) glMultMatrixf(self.interaction.trackball.matrix) # store the inverse of the current modelview. currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX)) self.modelView = numpy.transpose(currentModelView) self.inverseModelView = inv(numpy.transpose(currentModelView)) # render the scene. This will call the render function for each object in the scene self.scene.render() # draw the grid glDisable(GL_LIGHTING) glCallList(G_OBJ_PLANE) glPopMatrix() # flush the buffers so that the scene can be drawn glFlush()
def render_planar_update(self, rx, ry, rw, rh, x_scale=1, y_scale=1, shader=YUV2RGB_SHADER): log("%s.render_planar_update%s pixel_format=%s", self, (rx, ry, rw, rh, x_scale, y_scale, shader), self.pixel_format) if self.pixel_format not in ("YUV420P", "YUV422P", "YUV444P", "GBRP"): #not ready to render yet return glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[shader]) self.gl_marker("painting planar update, format %s", self.pixel_format) divs = get_subsampling_divs(self.pixel_format) glEnable(GL_FRAGMENT_PROGRAM_ARB) for texture, index in ((GL_TEXTURE0, TEX_Y), (GL_TEXTURE1, TEX_U), (GL_TEXTURE2, TEX_V)): glActiveTexture(texture) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[index]) tw, th = self.texture_size log("%s.render_planar_update(..) texture_size=%s, size=%s", self, self.texture_size, self.size) glBegin(GL_QUADS) for x,y in ((0, 0), (0, rh), (rw, rh), (rw, 0)): ax = min(tw, x) ay = min(th, y) for texture, index in ((GL_TEXTURE0, TEX_Y), (GL_TEXTURE1, TEX_U), (GL_TEXTURE2, TEX_V)): (div_w, div_h) = divs[index] glMultiTexCoord2i(texture, ax//div_w, ay//div_h) glVertex2i(int(rx+ax*x_scale), int(ry+ay*y_scale)) glEnd() for texture in (GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2): glActiveTexture(texture) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0) glDisable(GL_FRAGMENT_PROGRAM_ARB) glActiveTexture(GL_TEXTURE0)
def draw_conf_corner_bg_image( self, pos=None ): #bruce 070626 (pos argument is just for development & debugging) """ Redraw the previously grabbed conf_corner_bg_image, in the same place from which it was grabbed, or in the specified place (lower left corner of pos, in OpenGL window coords). Note: this modifies the OpenGL raster position. """ if not self._conf_corner_bg_image_data: print "self._conf_corner_bg_image_data not yet assigned" else: subwidth, subheight, width, height, gl_format, gl_type, image = self._conf_corner_bg_image_data if width != self.width or height != self.height: # I don't know if this can ever happen; if it can, caller might need # to detect this itself and do a full redraw. # (Or we might make this method return a boolean to indicate it.) print "can't draw self._conf_corner_bg_image_data -- glpane got resized" ### else: if pos is None: pos = (width - subwidth, height - subheight) x, y = pos self._set_raster_pos(x, y) glDisable( GL_DEPTH_TEST ) # otherwise it can be obscured by prior drawing into depth buffer # Note: doing more disables would speed up glDrawPixels, # but that doesn't matter unless we do it many times per frame. glDrawPixels(subwidth, subheight, gl_format, gl_type, image) glEnable(GL_DEPTH_TEST) pass return
def save_FBO(self): bw, bh = self.size glEnable(GL_TEXTURE_RECTANGLE_ARB) glBindFramebuffer(GL_READ_FRAMEBUFFER, self.offscreen_fbo) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0) glReadBuffer(GL_COLOR_ATTACHMENT0) glViewport(0, 0, bw, bh) size = bw*bh*4 data = numpy.empty(size) img_data = glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, 0, GL_BGRA, GL_UNSIGNED_BYTE, data) img = Image.frombuffer("RGBA", (bw, bh), img_data, "raw", "BGRA", bw*4) img = ImageOps.flip(img) kwargs = {} if SAVE_BUFFERS=="jpeg": kwargs = { "quality" : 0, "optimize" : False, } t = time.time() tstr = time.strftime("%H-%M-%S", time.localtime(t)) filename = "./W%i-FBO-%s.%03i.%s" % (self.wid, tstr, (t*1000)%1000, SAVE_BUFFERS) log("do_present_fbo: saving %4ix%-4i pixels, %7i bytes to %s", bw, bh, size, filename) img.save(filename, SAVE_BUFFERS, **kwargs) glBindFramebuffer(GL_READ_FRAMEBUFFER, 0) glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0) glDisable(GL_TEXTURE_RECTANGLE_ARB)
def drawwiresphere_worker(params): """ Draw a wireframe sphere. Receive parameters through a sequence so that this function and its parameters can be passed to another function for deferment. Right now this is only ColorSorter.schedule (see below) """ (color, pos, radius, detailLevel) = params ## assert detailLevel == 1 # true, but leave out for speed from utilities.debug_prefs import debug_pref, Choice_boolean_True #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it! newway = debug_pref("new wirespheres?", Choice_boolean_True) oldway = not newway # These objects want a constant line color even if they are selected or # highlighted. glColor3fv(color) glDisable(GL_LIGHTING) if oldway: glPolygonMode(GL_FRONT, GL_LINE) glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) glScale(radius,radius,radius) if oldway: glCallList(drawing_globals.sphereList[detailLevel]) else: glCallList(drawing_globals.wiresphere1list) glEnable(GL_LIGHTING) glPopMatrix() if oldway: glPolygonMode(GL_FRONT, GL_FILL) return
def draw(self, camera_matrix: numpy.ndarray, camera_position: PointCoordinatesAny = None): """ Draw the selection box :param camera_matrix: 4x4 transformation matrix for the camera :param camera_position: The position of the camera. Used to flip draw direction if camera inside box. :return: """ self._setup() if self._rebuild: self._create_geometry() self._draw_mode = GL_TRIANGLES transformation_matrix = numpy.matmul(camera_matrix, self.transformation_matrix) glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_POLYGON_BIT) # store opengl state if camera_position is not None and camera_position in self: glCullFace(GL_FRONT) else: glCullFace(GL_BACK) self.draw_start = 0 self.draw_count = 36 super()._draw(transformation_matrix) # draw the lines around the boxes glDisable(GL_DEPTH_TEST) self._draw_mode = GL_LINE_STRIP super()._draw(transformation_matrix) glPopAttrib() # reset to starting state
def draw_glpane_label_text(self, text): """ Draw a text label for the glpane as a whole. @note: called indirectly from GLPane.paintGL shortly after it calls _do_graphicsMode_Draw(), via GraphicsMode.draw_glpane_label """ #bruce 090219 moved this here from part of Part.draw_text_label # (after a temporary stop in the short-lived class PartDrawer); # the other part is now our caller GraphicsMode.draw_glpane_label. # (note: caller catches exceptions, so we don't have to bother) glDisable(GL_LIGHTING) glDisable(GL_DEPTH_TEST) # Note: disabling GL_DEPTH_TEST properly affects 2d renderText # (as used here), but not 3d renderText. For more info see # today's comments in Guides.py. [bruce 081204 comment] glPushMatrix() # REVIEW: needed? [bruce 081204 question] font = QFont(QString("Helvetica"), 24, QFont.Bold) self.qglColor(Qt.red) # this needs to be impossible to miss -- not nice-looking! #e tho it might be better to pick one of several bright colors # by hashing the partname, so as to change the color when the part changes. # this version of renderText uses window coords (0,0 at upper left) # rather than model coords (but I'm not sure what point on the string-image # we're setting the location of here -- guessing it's bottom-left corner): self.renderText(25,40, QString(text), font) glPopMatrix() glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) return
def drawFilledCircle(color, center, radius, normal): """ Scale, rotate/translate the unit circle properly. Added a filled circle variant, piotr 080405 """ glMatrixMode(GL_MODELVIEW) glPushMatrix() glColor3fv(color) glDisable(GL_LIGHTING) glTranslatef(center[0], center[1], center[2]) rQ = Q(V(0, 0, 1), normal) rotAngle = rQ.angle*180.0/pi #This may cause problems as proved before in Linear motor display. #rotation around (0, 0, 0) #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005: # rQ.x = 1.0 glRotatef(rotAngle, rQ.x, rQ.y, rQ.z) glScalef(radius, radius, 1.0) glCallList(drawing_globals.filledCircleList) glEnable(GL_LIGHTING) glPopMatrix() return
def compile_total_list(self): if self.total_list is not None: glNewList(self.total_list, GL_COMPILE) # reset a few things glDisable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) glMatrixMode(GL_PROJECTION) glLoadIdentity() glMatrixMode(GL_MODELVIEW) glLoadIdentity() # change the modelview to camera coordinates viewport = glGetIntegerv(GL_VIEWPORT) width = viewport[2] - viewport[0] height = viewport[3] - viewport[1] if width > height: w = float(width) / float(height) h = 1.0 else: w = 1.0 h = float(height) / float(width) glScalef(2/w, 2/h, 1.0) glCallList(self.draw_list) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEndList()
def drawRotateSign(color, pos1, pos2, radius, rotation = 0.0): """Rotate sign on top of the caps of the cylinder """ glPushMatrix() glColor3fv(color) vec = pos2-pos1 axis = norm(vec) glTranslatef(pos1[0], pos1[1], pos1[2]) ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes ## display problem on some platforms angle = -acos(axis[2])*180.0/pi if (axis[2]*axis[2] >= 1.0): glRotate(angle, 0.0, 1.0, 0.0) else: glRotate(angle, axis[1], -axis[0], 0.0) glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518 glScale(radius,radius,Numeric.dot(vec,vec)**.5) glLineWidth(2.0) glDisable(GL_LIGHTING) glCallList(drawing_globals.rotSignList) glEnable(GL_LIGHTING) glLineWidth(1.0) glPopMatrix() return
def draw_sorted(sorted_by_color): #russ 080320: factored out of finish(). """ Traverse color-sorted lists, invoking worker procedures. """ objects_drawn = 0 # Keep track and return. glEnable(GL_LIGHTING) for color, funcs in sorted_by_color.iteritems(): opacity = color[3] if opacity == -1: #piotr 080429: Opacity == -1 signals the "unshaded color". # Also, see my comment in "schedule". glDisable(GL_LIGHTING) # Don't forget to re-enable it! glColor3fv(color[:3]) else: apply_material(color) pass for func, params, name in funcs: objects_drawn += 1 if name != 0: glPushName(name) func(params) if name != 0: glPopName() pass continue if opacity == -1: glEnable(GL_LIGHTING) continue return objects_drawn