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 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 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 drawaxes(scale, point, color = black, coloraxes = False, dashEnabled = False): """ Draw axes. @note: used for both origin axes and point of view axes. @see: drawOriginAsSmallAxis (related code) """ n = scale glPushMatrix() glTranslate(point[0], point[1], point[2]) glDisable(GL_LIGHTING) if dashEnabled: #ninad060921 Note that we will only support dotted origin axis #(hidden lines) but not POV axis. (as it could be annoying) glLineStipple(5, 0xAAAA) glEnable(GL_LINE_STIPPLE) glDisable(GL_DEPTH_TEST) glColor3fv(color) if coloraxes: glColor3fv(red) glBegin(GL_LINES) glVertex( n, 0, 0) glVertex(-n, 0, 0) if coloraxes: glColor3fv(darkgreen) glVertex(0, n, 0) glVertex(0, -n, 0) if coloraxes: glColor3fv(blue) glVertex(0, 0, n) glVertex(0, 0, -n) glEnd() if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glPopMatrix() return
def drawaxes(scale, point, color=black, coloraxes=False, dashEnabled=False): """ Draw axes. @note: used for both origin axes and point of view axes. @see: drawOriginAsSmallAxis (related code) """ n = scale glPushMatrix() glTranslate(point[0], point[1], point[2]) glDisable(GL_LIGHTING) if dashEnabled: #ninad060921 Note that we will only support dotted origin axis #(hidden lines) but not POV axis. (as it could be annoying) glLineStipple(5, 0xAAAA) glEnable(GL_LINE_STIPPLE) glDisable(GL_DEPTH_TEST) glColor3fv(color) if coloraxes: glColor3fv(red) glBegin(GL_LINES) glVertex(n, 0, 0) glVertex(-n, 0, 0) if coloraxes: glColor3fv(darkgreen) glVertex(0, n, 0) glVertex(0, -n, 0) if coloraxes: glColor3fv(blue) glVertex(0, 0, n) glVertex(0, 0, -n) glEnd() if dashEnabled: glDisable(GL_LINE_STIPPLE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glPopMatrix() return
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if self.paint_box_line_width<=0: return glLineWidth(self.paint_box_line_width+0.5+int(encoding=="scroll")*2) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = get_paint_box_color(encoding) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if not OPENGL_PAINT_BOX>0: return glDisable(GL_TEXTURE_RECTANGLE_ARB) glDisable(GL_FRAGMENT_PROGRAM_ARB) glLineWidth(OPENGL_PAINT_BOX+0.5) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def paint_box(self, encoding, is_delta, x, y, w, h): #show region being painted if debug paint box is enabled only: if self.paint_box_line_width<=0: return glDisable(GL_TEXTURE_RECTANGLE_ARB) glDisable(GL_FRAGMENT_PROGRAM_ARB) glLineWidth(self.paint_box_line_width+0.5) if is_delta: glLineStipple(1, 0xaaaa) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) log("Painting colored box around %s screen update using: %s (delta=%s)", encoding, color, is_delta) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE)
def drawAxis(color, pos1, pos2, width = 2): #Ninad 060907 """ Draw chunk or jig axis """ #ninad060907 Note that this is different than draw # I may need this function to draw axis line. see its current implementation # in branch "ninad_060908_drawAxis_notAsAPropOfObject" glDisable(GL_LIGHTING) glColor3fv(color) glLineStipple(3, 0x1C47) # dash-dot-dash line glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) glBegin(GL_LINES) glVertex(pos1[0], pos1[1], pos1[2]) glVertex(pos2[0], pos2[1], pos2[2]) glEnd() if width != 1: glLineWidth(1.0) # restore default state glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def drawAxis(color, pos1, pos2, width=2): #Ninad 060907 """ Draw chunk or jig axis """ #ninad060907 Note that this is different than draw # I may need this function to draw axis line. see its current implementation # in branch "ninad_060908_drawAxis_notAsAPropOfObject" glDisable(GL_LIGHTING) glColor3fv(color) glLineStipple(3, 0x1C47) # dash-dot-dash line glEnable(GL_LINE_STIPPLE) if width != 1: glLineWidth(width) glBegin(GL_LINES) glVertex(pos1[0], pos1[1], pos1[2]) glVertex(pos2[0], pos2[1], pos2[2]) glEnd() if width != 1: glLineWidth(1.0) # restore default state glDisable(GL_LINE_STIPPLE) glEnable(GL_LIGHTING) return
def drawOriginAsSmallAxis(scale, origin, dashEnabled = False): """ Draws a small wireframe version of the origin. It is rendered as a 3D point at (0, 0, 0) with 3 small axes extending from it in the positive X, Y, Z directions. @see: drawaxes (related code) """ #Perhaps we should split this method into smaller methods? ninad060920 #Notes: #1. drawing arrowheads implemented on 060918 #2. ninad060921 Show the origin axes as dotted if behind the mode. #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the # object the arrowhead size is slightly smaller (otherwise some portion of # the the wireframe arrow shows up! #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with # glpane's scale - ninad060922 #ninad060922 in future , the following could be user preferences. if (dashEnabled): dashShrinkage = 0.9 else: dashShrinkage=1 x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01 xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025 arrowBase = scale * 0.0075 * dashShrinkage arrowHeight = scale * 0.035 * dashShrinkage lineWidth = 1.0 glPushMatrix() glTranslate(origin[0], origin[1], origin[2]) glDisable(GL_LIGHTING) glLineWidth(lineWidth) gleNumSides = gleGetNumSides() #Code to show hidden lines of the origin if some model obscures it # ninad060921 if dashEnabled: glLineStipple(2, 0xAAAA) glEnable(GL_LINE_STIPPLE) glDisable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) gleSetNumSides(5) else: gleSetNumSides(10) glBegin(GL_LINES) color = env.prefs[originAxisColor_prefs_key] glColor3fv(color) #start draw a point at origin . #ninad060922 is thinking about using GL_POINTS here glVertex(-x1, 0.0, 0.0) glVertex( x1, 0.0, 0.0) glVertex(0.0, -y1, 0.0) glVertex(0.0, y1, 0.0) glVertex(-x1, y1, z1) glVertex( x1, -y1, -z1) glVertex(x1, y1, z1) glVertex(-x1, -y1, -z1) glVertex(x1, y1, -z1) glVertex(-x1, -y1, z1) glVertex(-x1, y1, -z1) glVertex(x1, -y1, z1) #end draw a point at origin #start draw small origin axes glColor3fv(color) glVertex(xEnd, 0.0, 0.0) glVertex( 0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, yEnd, 0.0) glVertex(0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, 0.0, zEnd) glVertex(0.0, 0.0, 0.0) glEnd() #end draw lines glLineWidth(1.0) # End push matrix for drawing various lines in the origin and axes. glPopMatrix() #start draw solid arrow heads for X , Y and Z axes glPushMatrix() glDisable(GL_CULL_FACE) glColor3fv(color) glTranslatef(xEnd, 0.0, 0.0) glRotatef(90, 0.0, 1.0, 0.0) glePolyCone([[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight+1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0, yEnd, 0.0) glRotatef(-90, 1.0, 0.0, 0.0) glePolyCone([[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight+1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0,0.0,zEnd) glePolyCone([[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight+1]], None, [arrowBase, arrowBase, 0, 0]) #Disable line stipple and Enable Depth test if dashEnabled: glLineStipple(1, 0xAAAA) glDisable(GL_LINE_STIPPLE) glEnable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) gleSetNumSides(gleNumSides) glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glPopMatrix() #end draw solid arrow heads for X , Y and Z axes return
def drawOriginAsSmallAxis(scale, origin, dashEnabled=False): """ Draws a small wireframe version of the origin. It is rendered as a 3D point at (0, 0, 0) with 3 small axes extending from it in the positive X, Y, Z directions. @see: drawaxes (related code) """ #Perhaps we should split this method into smaller methods? ninad060920 #Notes: #1. drawing arrowheads implemented on 060918 #2. ninad060921 Show the origin axes as dotted if behind the mode. #3. ninad060922 The arrow heads are drawn as wireframe cones if behind the # object the arrowhead size is slightly smaller (otherwise some portion of # the the wireframe arrow shows up! #4 .Making origin non-zoomable is acheived by replacing hardcoded 'n' with # glpane's scale - ninad060922 #ninad060922 in future , the following could be user preferences. if (dashEnabled): dashShrinkage = 0.9 else: dashShrinkage = 1 x1, y1, z1 = scale * 0.01, scale * 0.01, scale * 0.01 xEnd, yEnd, zEnd = scale * 0.04, scale * 0.09, scale * 0.025 arrowBase = scale * 0.0075 * dashShrinkage arrowHeight = scale * 0.035 * dashShrinkage lineWidth = 1.0 glPushMatrix() glTranslate(origin[0], origin[1], origin[2]) glDisable(GL_LIGHTING) glLineWidth(lineWidth) gleNumSides = gleGetNumSides() #Code to show hidden lines of the origin if some model obscures it # ninad060921 if dashEnabled: glLineStipple(2, 0xAAAA) glEnable(GL_LINE_STIPPLE) glDisable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) gleSetNumSides(5) else: gleSetNumSides(10) glBegin(GL_LINES) color = env.prefs[originAxisColor_prefs_key] glColor3fv(color) #start draw a point at origin . #ninad060922 is thinking about using GL_POINTS here glVertex(-x1, 0.0, 0.0) glVertex(x1, 0.0, 0.0) glVertex(0.0, -y1, 0.0) glVertex(0.0, y1, 0.0) glVertex(-x1, y1, z1) glVertex(x1, -y1, -z1) glVertex(x1, y1, z1) glVertex(-x1, -y1, -z1) glVertex(x1, y1, -z1) glVertex(-x1, -y1, z1) glVertex(-x1, y1, -z1) glVertex(x1, -y1, z1) #end draw a point at origin #start draw small origin axes glColor3fv(color) glVertex(xEnd, 0.0, 0.0) glVertex(0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, yEnd, 0.0) glVertex(0.0, 0.0, 0.0) glColor3fv(color) glVertex(0.0, 0.0, zEnd) glVertex(0.0, 0.0, 0.0) glEnd() #end draw lines glLineWidth(1.0) # End push matrix for drawing various lines in the origin and axes. glPopMatrix() #start draw solid arrow heads for X , Y and Z axes glPushMatrix() glDisable(GL_CULL_FACE) glColor3fv(color) glTranslatef(xEnd, 0.0, 0.0) glRotatef(90, 0.0, 1.0, 0.0) glePolyCone( [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0, yEnd, 0.0) glRotatef(-90, 1.0, 0.0, 0.0) glePolyCone( [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]], None, [arrowBase, arrowBase, 0, 0]) glPopMatrix() glPushMatrix() glColor3fv(color) glTranslatef(0.0, 0.0, zEnd) glePolyCone( [[0, 0, -1], [0, 0, 0], [0, 0, arrowHeight], [0, 0, arrowHeight + 1]], None, [arrowBase, arrowBase, 0, 0]) #Disable line stipple and Enable Depth test if dashEnabled: glLineStipple(1, 0xAAAA) glDisable(GL_LINE_STIPPLE) glEnable(GL_DEPTH_TEST) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) gleSetNumSides(gleNumSides) glEnable(GL_CULL_FACE) glEnable(GL_LIGHTING) glPopMatrix() #end draw solid arrow heads for X , Y and Z axes return
def present_fbo(self, encoding, is_delta, x, y, w, h): if not self.paint_screen: return self.gl_marker("Presenting FBO on screen") # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() ww, wh = self.size if self.glconfig.is_double_buffered(): #refresh the whole window: x, y = 0, 0 w, h = ww, wh glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glBegin(GL_QUADS) #note how we invert coordinates.. glTexCoord2i(x, wh-y) glVertex2i(x, y) #top-left of window viewport glTexCoord2i(x, wh-y-h) glVertex2i(x, y+h) #bottom-left of window viewport glTexCoord2i(x+w, wh-y-h) glVertex2i(x+w, y+h) #bottom-right of window viewport glTexCoord2i(x+w, wh-y) glVertex2i(x+w, y) #top-right of window viewport glEnd() glDisable(GL_TEXTURE_RECTANGLE_ARB) #show region being painted: if OPENGL_PAINT_BOX: glLineWidth(1) if is_delta: glLineStipple(1, 0xf0f0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) glColor4f(*color) for px,py in ((x, y), (x+w, y), (x+w, y+h), (x, y+h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE) if self.paint_spinner: #add spinner: dim = min(ww/3.0, wh/3.0) t = time.time() count = int(t*4.0) bx = ww//2 by = wh//2 for i in range(8): #8 lines glBegin(GL_POLYGON) c = cv.trs[count%8][i] glColor4f(c, c, c, 1) mi1 = math.pi*i/4-math.pi/16 mi2 = math.pi*i/4+math.pi/16 glVertex2i(int(bx+math.sin(mi1)*10), int(by+math.cos(mi1)*10)) glVertex2i(int(bx+math.sin(mi1)*dim), int(by+math.cos(mi1)*dim)) glVertex2i(int(bx+math.sin(mi2)*dim), int(by+math.cos(mi2)*dim)) glVertex2i(int(bx+math.sin(mi2)*10), int(by+math.cos(mi2)*10)) glEnd() #if desired, paint window border if self.border and self.border.shown: #double size since half the line will be off-screen glLineWidth(self.border.size*2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px,py in ((0, 0), (ww, 0), (ww, wh), (0, wh)): glVertex2i(px, py) glEnd() # Show the backbuffer on screen self.gl_show() self.gl_frame_terminator() self.unset_rgb_paint_state() log("%s(%s, %s)", glBindFramebuffer, GL_FRAMEBUFFER, self.offscreen_fbo) glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.present_fbo() done", self)
def drawGPGridForPlane(glpane, color, line_type, w, h, uw, uh, up, right, displayLabels, originLocation, labelsDisplayStyle): """ Draw grid lines for a Grid from Plane PM. glpane = the glpane color = grid line and unit text color line_type is: 0=None, 1=Solid, 2=Dashed, or 3=Dotted w = width h = height uw = width spacing between grid lines uh = height spacing between grid lines """ if line_type == NO_LINE: return if uw > w: uw = w if uh > h: uh = h Z_OFF = 0.0 #0.001 glDisable(GL_LIGHTING) glColor3fv(color) hw = w/2.0; hh = h/2.0 if line_type > 1: glEnable(GL_LINE_STIPPLE) if line_type == DASHED_LINE: glLineStipple (1, 0x00FF) # dashed elif line_type == DOTTED_LINE: glLineStipple (1, 0x0101) # dotted else: print "drawGPGrid(): line_type '", line_type,"' is not valid. ", \ "Drawing dashed grid line." glLineStipple (1, 0x00FF) # dashed glBegin(GL_LINES) #Draw horizontal lines y1 = 0 while y1 > -hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 -= uh y1 = 0 while y1 < hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 += uh #Draw vertical lines x1 = 0 while x1 < hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 += uw x1 = 0 while x1 > -hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 -= uw glEnd() if line_type > 1: glDisable (GL_LINE_STIPPLE) # Draw unit labels for gridlines (in nm). text_color = color import sys if sys.platform == "darwin": # WARNING: Anything smaller than 9 pt on Mac OS X results in # un-rendered text. Not sure why. -- piotr 080616 font_size = 9 else: font_size = 8 text_offset = 0.3 # Offset from edge of border, in Angstroms. if displayLabels == True: if (originLocation == PLANE_ORIGIN_LOWER_LEFT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginLowerLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginUpperLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginUpperRight(h, w, hh, hw, uh, uw, text_offset, text_color,font_size, glpane) elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginLowerRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_LOWER_LEFT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesLowerLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesUpperLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesUpperRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesLowerRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) glEnable(GL_LIGHTING) return
def present_fbo(self, encoding, is_delta, x, y, w, h): if not self.paint_screen: return self.gl_marker("Presenting FBO on screen") # Change state to target screen instead of our FBO glBindFramebuffer(GL_FRAMEBUFFER, 0) if self._alpha_enabled: # transparent background: glClearColor(0.0, 0.0, 0.0, 0.0) else: # plain white no alpha: glClearColor(1.0, 1.0, 1.0, 1.0) # Draw FBO texture on screen self.set_rgb_paint_state() ww, wh = self.size if self.glconfig.is_double_buffered(): #refresh the whole window: x, y = 0, 0 w, h = ww, wh glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO]) if self._alpha_enabled: # support alpha channel if present: glEnablei(GL_BLEND, self.textures[TEX_FBO]) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glBegin(GL_QUADS) #note how we invert coordinates.. glTexCoord2i(x, wh - y) glVertex2i(x, y) #top-left of window viewport glTexCoord2i(x, wh - y - h) glVertex2i(x, y + h) #bottom-left of window viewport glTexCoord2i(x + w, wh - y - h) glVertex2i(x + w, y + h) #bottom-right of window viewport glTexCoord2i(x + w, wh - y) glVertex2i(x + w, y) #top-right of window viewport glEnd() glDisable(GL_TEXTURE_RECTANGLE_ARB) #show region being painted: if OPENGL_PAINT_BOX: glLineWidth(1) if is_delta: glLineStipple(1, 0xf0f0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_LOOP) color = BOX_COLORS.get(encoding, _DEFAULT_BOX_COLOR) glColor4f(*color) for px, py in ((x, y), (x + w, y), (x + w, y + h), (x, y + h)): glVertex2i(px, py) glEnd() if is_delta: glDisable(GL_LINE_STIPPLE) if self.paint_spinner: #add spinner: dim = min(ww / 3.0, wh / 3.0) t = time.time() count = int(t * 4.0) bx = ww // 2 by = wh // 2 for i in range(8): #8 lines glBegin(GL_POLYGON) c = cv.trs[count % 8][i] glColor4f(c, c, c, 1) mi1 = math.pi * i / 4 - math.pi / 16 mi2 = math.pi * i / 4 + math.pi / 16 glVertex2i(int(bx + math.sin(mi1) * 10), int(by + math.cos(mi1) * 10)) glVertex2i(int(bx + math.sin(mi1) * dim), int(by + math.cos(mi1) * dim)) glVertex2i(int(bx + math.sin(mi2) * dim), int(by + math.cos(mi2) * dim)) glVertex2i(int(bx + math.sin(mi2) * 10), int(by + math.cos(mi2) * 10)) glEnd() #if desired, paint window border if self.border and self.border.shown: #double size since half the line will be off-screen glLineWidth(self.border.size * 2) glBegin(GL_LINE_LOOP) glColor4f(self.border.red, self.border.green, self.border.blue, self.border.alpha) for px, py in ((0, 0), (ww, 0), (ww, wh), (0, wh)): glVertex2i(px, py) glEnd() # Show the backbuffer on screen self.gl_show() self.gl_frame_terminator() self.unset_rgb_paint_state() log("%s(%s, %s)", glBindFramebuffer, GL_FRAMEBUFFER, self.offscreen_fbo) glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo) log("%s.present_fbo() done", self)
def drawSiCGrid(color, line_type, w, h, up, right): """ Draw SiC grid. """ if line_type == NO_LINE: return XLen = sic_uLen * 3.0 YLen = sic_yU * 2.0 hw = w / 2.0 hh = h / 2.0 i1 = int(floor(-hw / XLen)) i2 = int(ceil(hw / XLen)) j1 = int(floor(-hh / YLen)) j2 = int(ceil(hh / YLen)) glDisable(GL_LIGHTING) glColor3fv(color) if line_type > 1: glEnable(GL_LINE_STIPPLE) if line_type == DASHED_LINE: glLineStipple(1, 0x00FF) # dashed elif line_type == DOTTED_LINE: glLineStipple(1, 0x0101) # dotted else: print "drawer.drawSiCGrid(): line_type '", line_type, \ "' is not valid. Drawing dashed grid line." glLineStipple(1, 0x00FF) # dashed glClipPlane(GL_CLIP_PLANE0, (1.0, 0.0, 0.0, hw)) glClipPlane(GL_CLIP_PLANE1, (-1.0, 0.0, 0.0, hw)) glClipPlane(GL_CLIP_PLANE2, (0.0, 1.0, 0.0, hh)) glClipPlane(GL_CLIP_PLANE3, (0.0, -1.0, 0.0, hh)) glEnable(GL_CLIP_PLANE0) glEnable(GL_CLIP_PLANE1) glEnable(GL_CLIP_PLANE2) glEnable(GL_CLIP_PLANE3) glPushMatrix() glTranslate(i1 * XLen, j1 * YLen, 0.0) for i in range(i1, i2): glPushMatrix() for j in range(j1, j2): glCallList(SiCGridList) glTranslate(0.0, YLen, 0.0) glPopMatrix() glTranslate(XLen, 0.0, 0.0) glPopMatrix() glDisable(GL_CLIP_PLANE0) glDisable(GL_CLIP_PLANE1) glDisable(GL_CLIP_PLANE2) glDisable(GL_CLIP_PLANE3) if line_type > 1: glDisable(GL_LINE_STIPPLE) xpos, ypos = hw, 0.0 f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up, rot90=False, glBegin=False) for j in range(j1, j2): yoff = j * YLen if -hh < yoff + ypos < hh: f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff) xpos, ypos = 0.0, hh f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up, rot90=True, glBegin=False) for i in range(2 * i1, 2 * i2): yoff = i * (XLen / 2) if -hw < yoff + xpos < hw: f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff) glEnable(GL_LIGHTING) return
def drawGPGrid(glpane, color, line_type, w, h, uw, uh, up, right): """ Draw grid lines for a Grid Plane. glpane = the glpane color = grid line and unit text color line_type is: 0=None, 1=Solid, 2=Dashed or 3=Dotted w = width h = height uw = width spacing between grid lines uh = height spacing between grid lines """ if line_type == NO_LINE: return if uw > w: uw = w if uh > h: uh = h Z_OFF = 0.0 #0.001 glDisable(GL_LIGHTING) glColor3fv(color) hw = w/2.0; hh = h/2.0 #glEnable(GL_LINE_SMOOTH) #glEnable(GL_BLEND) #glBlendFunc(GL_SRC_ALPHA, GL_ONE)#_MINUS_SRC_ALPHA) if line_type > 1: glEnable(GL_LINE_STIPPLE) if line_type == DASHED_LINE: glLineStipple (1, 0x00FF) # dashed elif line_type == DOTTED_LINE: glLineStipple (1, 0x0101) # dotted else: print "drawGPGrid(): line_type '", line_type, \ "' is not valid. Drawing dashed grid line." glLineStipple (1, 0x00FF) # dashed glBegin(GL_LINES) #Draw horizontal lines y1 = 0 while y1 > -hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 -= uh y1 = 0 while y1 < hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 += uh #Draw vertical lines x1 = 0 while x1 < hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 += uw x1 = 0 while x1 > -hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 -= uw glEnd() if line_type > 1: glDisable (GL_LINE_STIPPLE) # Draw unit labels for gridlines (in nm). text_color = color import sys if sys.platform == "darwin": # WARNING: Anything smaller than 9 pt on Mac OS X results in # un-rendered text. Not sure why. -- piotr 080616 font_size = 9 else: font_size = 8 text_offset = 0.5 # Offset from edge of border, in Angstroms. # Draw unit text labels for horizontal lines (nm) y1 = 0 while y1 > -hh: y1 -= uh drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) y1 = 0 while y1 < hh: drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) y1 += uh drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) # Draw unit text labels for vertical lines (nm). x1 = 0 while x1 < hw: drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) x1 += uw drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) x1 = 0 while x1 > -hw: drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) x1 -= uw drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) glEnable(GL_LIGHTING) return
def drawGPGrid(glpane, color, line_type, w, h, uw, uh, up, right): """ Draw grid lines for a Grid Plane. glpane = the glpane color = grid line and unit text color line_type is: 0=None, 1=Solid, 2=Dashed or 3=Dotted w = width h = height uw = width spacing between grid lines uh = height spacing between grid lines """ if line_type == NO_LINE: return if uw > w: uw = w if uh > h: uh = h Z_OFF = 0.0 #0.001 glDisable(GL_LIGHTING) glColor3fv(color) hw = w / 2.0 hh = h / 2.0 #glEnable(GL_LINE_SMOOTH) #glEnable(GL_BLEND) #glBlendFunc(GL_SRC_ALPHA, GL_ONE)#_MINUS_SRC_ALPHA) if line_type > 1: glEnable(GL_LINE_STIPPLE) if line_type == DASHED_LINE: glLineStipple(1, 0x00FF) # dashed elif line_type == DOTTED_LINE: glLineStipple(1, 0x0101) # dotted else: print "drawGPGrid(): line_type '", line_type, \ "' is not valid. Drawing dashed grid line." glLineStipple(1, 0x00FF) # dashed glBegin(GL_LINES) #Draw horizontal lines y1 = 0 while y1 > -hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 -= uh y1 = 0 while y1 < hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 += uh #Draw vertical lines x1 = 0 while x1 < hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 += uw x1 = 0 while x1 > -hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 -= uw glEnd() if line_type > 1: glDisable(GL_LINE_STIPPLE) # Draw unit labels for gridlines (in nm). text_color = color import sys if sys.platform == "darwin": # WARNING: Anything smaller than 9 pt on Mac OS X results in # un-rendered text. Not sure why. -- piotr 080616 font_size = 9 else: font_size = 8 text_offset = 0.5 # Offset from edge of border, in Angstroms. # Draw unit text labels for horizontal lines (nm) y1 = 0 while y1 > -hh: y1 -= uh drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) y1 = 0 while y1 < hh: drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) y1 += uh drawtext("%g" % (-y1 / 10.0), text_color, V(hw + text_offset, y1, 0.0), font_size, glpane) # Draw unit text labels for vertical lines (nm). x1 = 0 while x1 < hw: drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) x1 += uw drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) x1 = 0 while x1 > -hw: drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) x1 -= uw drawtext("%g" % (x1 / 10.0), text_color, V(x1, hh + text_offset, 0.0), font_size, glpane) glEnable(GL_LIGHTING) return
def drawSiCGrid(color, line_type, w, h, up, right): """ Draw SiC grid. """ if line_type == NO_LINE: return XLen = sic_uLen * 3.0 YLen = sic_yU * 2.0 hw = w/2.0; hh = h/2.0 i1 = int(floor(-hw/XLen)) i2 = int(ceil(hw/XLen)) j1 = int(floor(-hh/YLen)) j2 = int(ceil(hh/YLen)) glDisable(GL_LIGHTING) glColor3fv(color) if line_type > 1: glEnable(GL_LINE_STIPPLE) if line_type == DASHED_LINE: glLineStipple (1, 0x00FF) # dashed elif line_type == DOTTED_LINE: glLineStipple (1, 0x0101) # dotted else: print "drawer.drawSiCGrid(): line_type '", line_type, \ "' is not valid. Drawing dashed grid line." glLineStipple (1, 0x00FF) # dashed glClipPlane(GL_CLIP_PLANE0, (1.0, 0.0, 0.0, hw)) glClipPlane(GL_CLIP_PLANE1, (-1.0, 0.0, 0.0, hw)) glClipPlane(GL_CLIP_PLANE2, (0.0, 1.0, 0.0, hh)) glClipPlane(GL_CLIP_PLANE3, (0.0, -1.0, 0.0, hh)) glEnable(GL_CLIP_PLANE0) glEnable(GL_CLIP_PLANE1) glEnable(GL_CLIP_PLANE2) glEnable(GL_CLIP_PLANE3) glPushMatrix() glTranslate(i1*XLen, j1*YLen, 0.0) for i in range(i1, i2): glPushMatrix() for j in range(j1, j2): glCallList(SiCGridList) glTranslate(0.0, YLen, 0.0) glPopMatrix() glTranslate(XLen, 0.0, 0.0) glPopMatrix() glDisable(GL_CLIP_PLANE0) glDisable(GL_CLIP_PLANE1) glDisable(GL_CLIP_PLANE2) glDisable(GL_CLIP_PLANE3) if line_type > 1: glDisable (GL_LINE_STIPPLE) xpos, ypos = hw, 0.0 f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up, rot90=False, glBegin=False) for j in range(j1, j2): yoff = j * YLen if -hh < yoff + ypos < hh: f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff) xpos, ypos = 0.0, hh f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up, rot90=True, glBegin=False) for i in range(2*i1, 2*i2): yoff = i * (XLen/2) if -hw < yoff + xpos < hw: f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff) glEnable(GL_LIGHTING) return
def drawGPGridForPlane(glpane, color, line_type, w, h, uw, uh, up, right, displayLabels, originLocation, labelsDisplayStyle): """ Draw grid lines for a Grid from Plane PM. glpane = the glpane color = grid line and unit text color line_type is: 0=None, 1=Solid, 2=Dashed, or 3=Dotted w = width h = height uw = width spacing between grid lines uh = height spacing between grid lines """ if line_type == NO_LINE: return if uw > w: uw = w if uh > h: uh = h Z_OFF = 0.0 #0.001 glDisable(GL_LIGHTING) glColor3fv(color) hw = w / 2.0 hh = h / 2.0 if line_type > 1: glEnable(GL_LINE_STIPPLE) if line_type == DASHED_LINE: glLineStipple(1, 0x00FF) # dashed elif line_type == DOTTED_LINE: glLineStipple(1, 0x0101) # dotted else: print "drawGPGrid(): line_type '", line_type,"' is not valid. ", \ "Drawing dashed grid line." glLineStipple(1, 0x00FF) # dashed glBegin(GL_LINES) #Draw horizontal lines y1 = 0 while y1 > -hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 -= uh y1 = 0 while y1 < hh: glVertex3f(-hw, y1, Z_OFF) glVertex3f(hw, y1, Z_OFF) y1 += uh #Draw vertical lines x1 = 0 while x1 < hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 += uw x1 = 0 while x1 > -hw: glVertex3f(x1, hh, Z_OFF) glVertex3f(x1, -hh, Z_OFF) x1 -= uw glEnd() if line_type > 1: glDisable(GL_LINE_STIPPLE) # Draw unit labels for gridlines (in nm). text_color = color import sys if sys.platform == "darwin": # WARNING: Anything smaller than 9 pt on Mac OS X results in # un-rendered text. Not sure why. -- piotr 080616 font_size = 9 else: font_size = 8 text_offset = 0.3 # Offset from edge of border, in Angstroms. if displayLabels == True: if (originLocation == PLANE_ORIGIN_LOWER_LEFT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginLowerLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginUpperLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginUpperRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and labelsDisplayStyle == LABELS_ALONG_ORIGIN): displayLabelsAlongOriginLowerRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_LOWER_LEFT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesLowerLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_LEFT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesUpperLeft(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_UPPER_RIGHT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesUpperRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) elif (originLocation == PLANE_ORIGIN_LOWER_RIGHT and labelsDisplayStyle == LABELS_ALONG_PLANE_EDGES): displayLabelsAlongPlaneEdgesLowerRight(h, w, hh, hw, uh, uw, text_offset, text_color, font_size, glpane) glEnable(GL_LIGHTING) return