def draw_callback_px(self, context): #print("callback_px") # Maybe print a nice red circle in some corner bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS) FONT_RGBA = (0.8, 0.1, 0.1, 0.5) bgl.glColor4f(*FONT_RGBA) font_size = 11 DPI = 72 blf.size(0, font_size, DPI) msg = "Logging..." msg_w, msg_h = blf.dimensions(0, msg) pos_x = context.region.width - msg_w pos_y = font_size / 2 blf.position(0, pos_x, pos_y, 0) #blf.position(0, 10, 10, 0) blf.draw(0, msg) bgl.glPopAttrib() pass
def draw_preview(self): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glBegin(bgl.GL_QUADS) # TODO: not use immediate mode bgl.glColor4f(0,0,0.2,0.5) bgl.glVertex2f(-1, -1) bgl.glVertex2f( 1, -1) bgl.glColor4f(0,0,0.2,0) bgl.glVertex2f( 1, 1) bgl.glVertex2f(-1, 1) bgl.glEnd() bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopAttrib()
def draw_callback_preview(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.draw_preview() except: interactive_physics_handle_exception() bgl.glPopAttrib() # restore OpenGL attributes
def draw_callback_postview(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.draw_postview(context) except: self.handle_exception() bgl.glPopAttrib() # restore OpenGL attributes
def crosshairs(): """ Show crosshais in Manipulation Mode Use the OpenGL-Wrapper to draw the image """ imageHeight = windowHeight * 0.05 imageWidth = imageHeight x = windowWidth * 0.5 - imageWidth / 2 y = windowHeight * 0.5 - imageHeight / 2 gl_position = [[x, y], [x + imageWidth, y], [x + imageWidth, y + imageHeight], [x, y + imageHeight]] view_buf = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf) view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list # Save the state bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # Disable depth test so we always draw over things bgl.glDisable(bgl.GL_DEPTH_TEST) # Disable lighting so everything is shadless bgl.glDisable(bgl.GL_LIGHTING) # Unbinding the texture prevents BGUI frames from somehow picking up on # color of the last used texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) # Make sure we're using smooth shading instead of flat bgl.glShadeModel(bgl.GL_SMOOTH) # Setup the matrices bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.gluOrtho2D(0, view[2], 0, view[3]) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glEnable(bgl.GL_TEXTURE_2D) # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) # Bind the texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id) # Draw the textured quad bgl.glColor4f(1, 1, 1, 1) bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL) bgl.glPolygonOffset(1.0, 1.0) bgl.glBegin(bgl.GL_QUADS) for i in range(4): bgl.glTexCoord2f(texco[i][0], texco[i][1]) bgl.glVertex2f(gl_position[i][0], gl_position[i][1]) bgl.glEnd() bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glPopAttrib()
def draw_postpixel(self): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) bgl.glEnable(bgl.GL_BLEND) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glColor4f(1,0,0,0.2) # TODO: use window background color?? bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glBegin(bgl.GL_QUADS) # TODO: not use immediate mode bgl.glVertex2f(-1, -1) bgl.glVertex2f( 1, -1) bgl.glVertex2f( 1, 1) bgl.glVertex2f(-1, 1) bgl.glEnd() bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopAttrib()
def draw_underline_in_strip(strip_coords, pixel_size_x, color): from bgl import glColor4f, glRectf, glEnable, glDisable, GL_BLEND import bgl context = bpy.context # Strip coords s_x1, s_y1, s_x2, s_y2 = strip_coords # be careful not to draw over the current frame line cf_x = context.scene.frame_current_final bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_LINE_BIT) glColor4f(*color) glEnable(GL_BLEND) bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(s_x1, s_y1) if s_x1 < cf_x < s_x2: # Bad luck, the line passes our strip bgl.glVertex2f(cf_x - pixel_size_x, s_y1) bgl.glVertex2f(cf_x + pixel_size_x, s_y1) bgl.glVertex2f(s_x2, s_y1) bgl.glEnd() bgl.glPopAttrib()
def draw_callback_px(self, context): #print("callback_px") # Maybe print a nice red circle in some corner bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS) FONT_RGBA = (0.8, 0.1, 0.1, 0.5) bgl.glColor4f(*FONT_RGBA) font_size = 11 DPI = 72 blf.size(0, font_size, DPI) msg = "Logging..." msg_w,msg_h = blf.dimensions(0, msg) pos_x = context.region.width - msg_w pos_y = font_size / 2 blf.position(0, pos_x, pos_y, 0) #blf.position(0, 10, 10, 0) blf.draw(0, msg) bgl.glPopAttrib() pass
def draw_callback_postview(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes self.draw_postview(context) if len(self.selectCntrl): cntrlLength = len(self.selectCntrl) for x in range(0,cntrlLength): # assuming that we have only one control point, so if # anything is selected it would be the only point p111 = self.selectCntrl[x] t111 = p111.to_tuple() vrot = context.space_data.region_3d.view_rotation dx = (vrot * Vector((1,0,0))).normalized() # compute right dir relative to view dy = (vrot * Vector((0,1,0))).normalized() # compute up dir relative to view px = tuple(p111 + dx*0.5) py = tuple(p111 + dy*0.5) # highlight the point bgl.glColor3f(1,1,0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*t111) bgl.glEnd() # draw lines to indicate right (red) and up (green) bgl.glBegin(bgl.GL_LINES) bgl.glColor3f(1,0,0) bgl.glVertex3f(*t111) bgl.glVertex3f(*px) bgl.glColor3f(0,1,0) bgl.glVertex3f(*t111) bgl.glVertex3f(*py) bgl.glEnd() bgl.glPopAttrib() # restore OpenGL attributes
def draw_callback_postpixel(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.draw_postpixel() except: bricker_handle_exception() bgl.glPopAttrib() # restore OpenGL attributes
def draw_callback_px(self, context): region = context.region rv3d = context.space_data.region_3d init2d = self.obLoc[:2] dest2d = self.mouseCoNew[:2] # Line drawing bgl.glPushAttrib(bgl.GL_ENABLE_BIT) # glPushAttrib is done to return everything to normal after drawing bgl.glLineStipple(2, 0x9999) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1) #bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glVertex2f(*init2d) bgl.glVertex2f(*dest2d) bgl.glEnd() bgl.glPopAttrib() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw(self): context = bpy.context scene = context.scene view = context.area.spaces.active if context.mode != self.last_mode: self.last_mode = context.mode self.cleanup() if view.viewport_shade != 'TEXTURED': return bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS) bgl.glShadeModel(bgl.GL_SMOOTH) for obj in context.visible_objects: if (obj.type == 'MESH' and obj.data.edges and not obj.data.polygons and not # obj.select and not obj == context.edit_object): cache = self.obj_cache.get(hash(obj)) if cache is None: cache = LineObjCache() self.obj_cache[hash(obj)] = cache cache.draw(self, obj) bgl.glPopAttrib()
def draw_callback_postview(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes self.draw_postview(context) if len(self.selectCntrl): cntrlLength = len(self.selectCntrl) for x in range(0, cntrlLength): # assuming that we have only one control point, so if # anything is selected it would be the only point p111 = self.selectCntrl[x] t111 = p111.to_tuple() vrot = context.space_data.region_3d.view_rotation dx = (vrot * Vector( (1, 0, 0))).normalized() # compute right dir relative to view dy = (vrot * Vector( (0, 1, 0))).normalized() # compute up dir relative to view px = tuple(p111 + dx * 0.5) py = tuple(p111 + dy * 0.5) # highlight the point bgl.glColor3f(1, 1, 0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*t111) bgl.glEnd() # draw lines to indicate right (red) and up (green) bgl.glBegin(bgl.GL_LINES) bgl.glColor3f(1, 0, 0) bgl.glVertex3f(*t111) bgl.glVertex3f(*px) bgl.glColor3f(0, 1, 0) bgl.glVertex3f(*t111) bgl.glVertex3f(*py) bgl.glEnd() bgl.glPopAttrib() # restore OpenGL attributes
def draw_viewport_2d(self, context): bgl.glPushAttrib( bgl.GL_DEPTH_BUFFER_BIT | bgl.GL_LINE_BIT | bgl.GL_COLOR_BUFFER_BIT | bgl.GL_CURRENT_BIT) bgl.glEnable(bgl.GL_BLEND) bgl.glDepthFunc(bgl.GL_ALWAYS) bgl.glLineWidth(1) if self.started: ax, ay = self.mouse_a bx, by = self.mouse_b bgl.glBegin(bgl.GL_LINES) bgl.glColor4f(0, 0, 0, 1) bgl.glVertex2f(ax + 1, ay) bgl.glVertex2f(bx + 1, by) bgl.glVertex2f(ax - 1, ay) bgl.glVertex2f(bx - 1, by) bgl.glVertex2f(ax, ay + 1) bgl.glVertex2f(bx, by + 1) bgl.glVertex2f(ax, ay - 1) bgl.glVertex2f(bx, by - 1) bgl.glColor4f(1, 1, 1, 1) bgl.glVertex2f(ax, ay) bgl.glVertex2f(bx, by) bgl.glEnd() mx, my = self.mouse_now my -= 16 bgl.glBegin(bgl.GL_QUADS) bgl.glColor3f(0, 0, 0) bgl.glVertex2f(mx - 9, my - 8) bgl.glVertex2f(mx, my + 1) bgl.glVertex2f(mx + 9, my - 8) bgl.glVertex2f(mx, my - 17) bgl.glEnd() bgl.glBegin(bgl.GL_TRIANGLES) bgl.glColor3f(*self.color_a) bgl.glVertex2f(mx - 8, my - 8) bgl.glVertex2f(mx, my) bgl.glVertex2f(mx, my - 16) bgl.glEnd() bgl.glBegin(bgl.GL_TRIANGLES) bgl.glColor3f(*self.color_b) bgl.glVertex2f(mx, my) bgl.glVertex2f(mx + 8, my - 8) bgl.glVertex2f(mx, my - 16) bgl.glEnd() bgl.glPopAttrib();
def draw_callback_postview(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes if self.sublvl > 0: self.draw_postview(context, self.submesh, False) self.draw_postview(context, self.mesh, True) bgl.glPopAttrib() # restore OpenGL attributes
def _end(self): # print("_end") bgl.glEnd() bgl.glPopAttrib() bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_postpixel(self, context): if not registered_check(): return bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.draw_postpixel(context) except: self.handle_exception() bgl.glPopAttrib() # restore OpenGL attributes
def crosshairs(): """ Show crosshais in Manipulation Mode Use the OpenGL-Wrapper to draw the image """ imageHeight = windowHeight * 0.05 imageWidth = imageHeight x = windowWidth * 0.5 - imageWidth/2 y = windowHeight * 0.5 - imageHeight/2 gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]] view_buf = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf) view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list # Save the state bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # Disable depth test so we always draw over things bgl.glDisable(bgl.GL_DEPTH_TEST) # Disable lighting so everything is shadless bgl.glDisable(bgl.GL_LIGHTING) # Unbinding the texture prevents BGUI frames from somehow picking up on # color of the last used texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) # Make sure we're using smooth shading instead of flat bgl.glShadeModel(bgl.GL_SMOOTH) # Setup the matrices bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.gluOrtho2D(0, view[2], 0, view[3]) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glEnable(bgl.GL_TEXTURE_2D) # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) # Bind the texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id) # Draw the textured quad bgl.glColor4f(1, 1, 1, 1) bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL) bgl.glPolygonOffset(1.0, 1.0) bgl.glBegin(bgl.GL_QUADS) for i in range(4): bgl.glTexCoord2f(texco[i][0], texco[i][1]) bgl.glVertex2f(gl_position[i][0], gl_position[i][1]) bgl.glEnd() bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glPopAttrib()
def draw_callback_postpixel(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.draw_postpixel(context) except: self.handle_exception() if self.settings.show_help and self.help_box: self.help_box.draw() bgl.glPopAttrib() # restore OpenGL attributes
def draw_callback_px(self, context): bgl.glPushAttrib(bgl.GL_ENABLE_BIT) # glPushAttrib is done to return everything to normal after drawing bgl.glLineStipple(10, 0x9999) bgl.glEnable(bgl.GL_LINE_STIPPLE) # 50% alpha, 2 pixel width line bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, 0.8) bgl.glLineWidth(5) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in self.mouse_path: bgl.glVertex2i(x, y) bgl.glEnd() bgl.glPopAttrib() bgl.glEnable(bgl.GL_BLEND) # ...api_current/bpy.types.Area.html?highlight=bpy.types.area header_height = context.area.regions[0].height # 26px width = context.area.width height = context.area.height - header_height p1_2d = (0,0) p2_2d = (width, height) p3_2d = (width, 0) p4_2d = (0, height) # green line bgl.glLineWidth(3) draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d) # yellow line bgl.glLineWidth(5) draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d) # white circle bgl.glLineWidth(4) draw_circle_2d((1.0, 1.0, 1.0, 0.8), width/2, height/2, 70, 360) # red circle bgl.glLineWidth(5) draw_circle_2d((1.0, 0.0, 0.0, 0.4), width/2, height/2, 230, 5) # draw text draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path))) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): bgl.glPushAttrib(bgl.GL_ENABLE_BIT) # glPushAttrib is done to return everything to normal after drawing bgl.glLineStipple(10, 0x9999) bgl.glEnable(bgl.GL_LINE_STIPPLE) # 50% alpha, 2 pixel width line bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, 0.8) bgl.glLineWidth(5) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in self.mouse_path: bgl.glVertex2i(x, y) bgl.glEnd() bgl.glPopAttrib() bgl.glEnable(bgl.GL_BLEND) # ...api_current/bpy.types.Area.html?highlight=bpy.types.area header_height = context.area.regions[0].height # 26px width = context.area.width height = context.area.height - header_height p1_2d = (0, 0) p2_2d = (width, height) p3_2d = (width, 0) p4_2d = (0, height) # green line bgl.glLineWidth(3) draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d) # yellow line bgl.glLineWidth(5) draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d) # white circle bgl.glLineWidth(4) draw_circle_2d((1.0, 1.0, 1.0, 0.8), width / 2, height / 2, 70, 360) # red circle bgl.glLineWidth(5) draw_circle_2d((1.0, 0.0, 0.0, 0.4), width / 2, height / 2, 230, 5) # draw text draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path))) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_postview(self, context): if not still_registered(self): return self.drawing.update_dpi() self.drawing.set_font_size(12, force=True) self.drawing.point_size(1) self.drawing.line_width(1) bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.rfctx.draw_postview() except: self.handle_exception() bgl.glPopAttrib() # restore OpenGL attributes
def draw3d(self): '''描画を行う(3次元)''' if (self.fwScene is None) or (self.fwScene.GetPHScene() is None): return # --- <!!> --- if bpy.context.scene.spr_debug_draw_enabled == 1: render = spbapi_cpp.GetGRRender() if not render is None: bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) self.fwScene.DrawPHScene(render) bgl.glPopAttrib()
def color_placing(): """ Draw the green rectangle via OpenGL-Wrapper """ imageHeight = windowHeight * 0.05 imageWidth = imageHeight x = windowWidth * 0.5 - imageWidth / 2 y = windowHeight * 0.5 - imageHeight / 2 gl_position = [[x, y], [x + imageWidth, y], [x + imageWidth, y + imageHeight], [x, y + imageHeight]] view_buf = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf) view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list # Save the state bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # Disable depth test so we always draw over things bgl.glDisable(bgl.GL_DEPTH_TEST) # Disable lighting so everything is shadless bgl.glDisable(bgl.GL_LIGHTING) # Make sure we're using smooth shading instead of flat bgl.glShadeModel(bgl.GL_SMOOTH) # Setup the matrices bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.gluOrtho2D(0, view[2], 0, view[3]) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) # Draw the colored quad bgl.glColor4f(0, 1, 0, 0.25) bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL) bgl.glPolygonOffset(1.0, 1.0) bgl.glBegin(bgl.GL_QUADS) for i in range(4): bgl.glTexCoord2f(texco[i][0], texco[i][1]) bgl.glVertex2f(gl_position[i][0], gl_position[i][1]) bgl.glEnd() bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glPopAttrib()
def color_placing(): """ Draw the green rectangle via OpenGL-Wrapper """ imageHeight = windowHeight * 0.05 imageWidth = imageHeight x = windowWidth * 0.5 - imageWidth/2 y = windowHeight * 0.5 - imageHeight/2 gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]] view_buf = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf) view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list # Save the state bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # Disable depth test so we always draw over things bgl.glDisable(bgl.GL_DEPTH_TEST) # Disable lighting so everything is shadless bgl.glDisable(bgl.GL_LIGHTING) # Make sure we're using smooth shading instead of flat bgl.glShadeModel(bgl.GL_SMOOTH) # Setup the matrices bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.gluOrtho2D(0, view[2], 0, view[3]) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) # Draw the colored quad bgl.glColor4f(0, 1, 0, 0.25) bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL) bgl.glPolygonOffset(1.0, 1.0) bgl.glBegin(bgl.GL_QUADS) for i in range(4): bgl.glTexCoord2f(texco[i][0], texco[i][1]) bgl.glVertex2f(gl_position[i][0], gl_position[i][1]) bgl.glEnd() bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glPopAttrib()
def push_attrib(cls, mask=bgl.GL_ALL_ATTRIB_BITS, matrix=True): """with文で使用する。 with GLSettings.push_attrib(): ... :rtype: GCM """ bgl.glPushAttrib(mask) modelview = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX) projection = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX) yield if matrix: cls._load_matrix(modelview, projection) bgl.glPopAttrib()
def draw_callback_postpixel(self, context): if not still_registered(self): return self.drawing.update_dpi() self.drawing.set_font_size(12, force=True) self.drawing.point_size(1) self.drawing.line_width(1) bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes try: self.rfctx.draw_postpixel() except: dprint('Exception in draw_postpixel') self.handle_exception() #if self.settings.show_help and self.help_box: self.help_box.draw() bgl.glPopAttrib() # restore OpenGL attributes
def _cc_region_draw_cover(self, a): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glColor4f(0, 0, 0, 0.5) # TODO: use window background color?? bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glBegin(bgl.GL_QUADS) # TODO: not use immediate mode bgl.glVertex2f(-1, -1) bgl.glVertex2f(1, -1) bgl.glVertex2f(1, 1) bgl.glVertex2f(-1, 1) bgl.glEnd() bgl.glPopMatrix() bgl.glPopAttrib()
def draw_callback_px(context): # Note that the "context" passed in here is a regular dictionary and not the Blender context global screen_display_lines pid = None if 'mcell' in bpy.context.scene: mcell = bpy.context.scene.mcell if 'run_simulation' in mcell: rs = mcell.run_simulation if len(rs.processes_list) > 0: pid_str = rs.processes_list[rs.active_process_index].name pid = pid_str.split(',')[0].split()[1] bgl.glPushAttrib(bgl.GL_ENABLE_BIT) if parameter_dictionary['Clear']['val']: bgl.glClearColor(0.0, 0.0, 0.0, 1.0) bgl.glClear(bgl.GL_COLOR_BUFFER_BIT) font_id = 0 # XXX, need to find out how best to get this. y_pos = 15 * (scroll_offset + 1) if pid and (pid in screen_display_lines): for l in screen_display_lines[pid]: blf.position(font_id, 15, y_pos, 0) y_pos += 15 blf.size(font_id, 14, 72) # fontid, size, DPI bgl.glColor4f(1.0, 1.0, 1.0, 0.5) blf.draw(font_id, l) else: keys = screen_display_lines.keys() for k in keys: for l in screen_display_lines[k]: blf.position(font_id, 15, y_pos, 0) y_pos += 15 blf.size(font_id, 14, 72) # fontid, size, DPI bgl.glColor4f(1.0, 1.0, 1.0, 0.5) blf.draw(font_id, l) # 100% alpha, 2 pixel width line bgl.glEnable(bgl.GL_BLEND) bgl.glPopAttrib() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_cover(self, context): if not still_registered(self): return bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glColor4f(0,0,0,0.5) # TODO: use window background color?? bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glBegin(bgl.GL_QUADS) # TODO: not use immediate mode bgl.glVertex2f(-1, -1) bgl.glVertex2f( 1, -1) bgl.glVertex2f( 1, 1) bgl.glVertex2f(-1, 1) bgl.glEnd() bgl.glPopMatrix() bgl.glPopAttrib()
def draw_callback_cover(self, context): if not still_registered(self): return bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glColor4f(0, 0, 0, 0.5) # TODO: use window background color?? bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glBegin(bgl.GL_QUADS) # TODO: not use immediate mode bgl.glVertex2f(-1, -1) bgl.glVertex2f(1, -1) bgl.glVertex2f(1, 1) bgl.glVertex2f(-1, 1) bgl.glEnd() bgl.glPopMatrix() bgl.glPopAttrib()
def draw_callback_px(): import bgl context = bpy.context if not context.scene.sequence_editor: return strips = shown_strips(context) if not strips: return region = context.region xwin1, ywin1 = region.view2d.region_to_view(0, 0) xwin2, ywin2 = region.view2d.region_to_view(region.width, region.height) one_pixel_further_x, one_pixel_further_y = region.view2d.region_to_view( 1, 1) pixel_size_x = one_pixel_further_x - xwin1 bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_LINE_BIT) bgl.glColor4f(1.0, 1.0, 0.0, 1.0) bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINES) for strip in strips: hl = highlights(strip) if not hl: continue # Get corners (x1, y1), (x2, y2) of the strip rectangle in px region coords strip_coords = get_strip_rectf(strip) # check if any of the coordinates are out of bounds if strip_coords[0] > xwin2 or strip_coords[2] < xwin1 or strip_coords[1] > ywin2 or \ strip_coords[3] < ywin1: continue # Draw for rel_frame in hl: abs_frame = rel_to_abs(strip, rel_frame) bgl.glVertex2f(abs_frame, strip_coords[1]) bgl.glVertex2f(abs_frame, strip_coords[3]) bgl.glEnd() bgl.glPopAttrib()
def draw_action_header_text(self, x, y, speaker, action, margin=4): bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_ENABLE_BIT) font_id = 0 x = x + margin y = y + margin # bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.size(font_id, 16, 64) blf.position(font_id, x, y, 0.0) baking = "" if bpy.types.BakeSoundPanel.baking: baking = "(BAKING....)" s = "[%s] %s %s" % (action["channel_name"], action.name, baking) blf.draw(font_id, s) blf.size(font_id, 20, 36) blf.position(font_id, x + 10 * len(s), y, 0.0) blf.draw(font_id, action["wavfile"]) bgl.glPopAttrib()
def draw_viewport_2d(self, context): data = context.active_object.data vps = data.vertex_paint_settings bgl.glPushAttrib( bgl.GL_DEPTH_BUFFER_BIT | bgl.GL_LINE_BIT | bgl.GL_COLOR_BUFFER_BIT | bgl.GL_CURRENT_BIT) bgl.glEnable(bgl.GL_BLEND) bgl.glDepthFunc(bgl.GL_ALWAYS) bgl.glLineWidth(1) bgl.glBegin(bgl.GL_LINES) mx, my = self.mouse_pos radius = vps.radius ticks = radius if ticks % 2 != 0: ticks -= 1 ticks = min(512, max(16, ticks)) bgl.glColor4f(0, 0, 0, 1) for i in range(ticks): v = i / float(ticks) x = mx + math.cos(v * math.pi * 2) * radius y = my + math.sin(v * math.pi * 2) * radius bgl.glVertex2f(x, y) bgl.glVertex2f(x, y) bgl.glColor4f(1, 1, 1, 1) for i in range(ticks): v = i / float(ticks) x = mx + math.cos(v * math.pi * 2) * radius y = my + math.sin(v * math.pi * 2) * radius bgl.glVertex2f(x, y) bgl.glEnd() bgl.glPopAttrib();
def draw_opengl(self, context): region = self._window_region(context) if self.placed_first_point: help_text = "Command Help:\nLEFT CLICK: Place Second Point\nRIGHT CLICK: Cancel Command" else: help_text = "Command Help:\nLEFT CLICK: Place First Point\nRIGHT CLICK: Cancel Command" if self.found_snap_point: help_text += "\n SNAP TO VERTEX" help_box = TextBox(x=0, y=0, width=500, height=0, border=10, margin=100, message=help_text) help_box.x = (self.mouse_x + (help_box.width) / 2 + 10) - region.x help_box.y = (self.mouse_y - 10) - region.y help_box.draw() # SNAP POINT bgl.glPushAttrib(bgl.GL_ENABLE_BIT) bgl.glColor4f(255, 0.0, 0.0, 1.0) bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(10) bgl.glBegin(bgl.GL_POINTS) if self.snapping_point_2d: bgl.glVertex2f(self.snapping_point_2d[0], self.snapping_point_2d[1]) bgl.glEnd() bgl.glPopAttrib() # restore opengl defaults bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_strip_conflict(strip_coords, pixel_size_x): """Draws conflicting states between strips.""" import bgl s_x1, s_y1, s_x2, s_y2 = strip_coords bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_LINE_BIT) # Always draw the full rectangle, the conflict should be resolved and thus stand out. bgl.glColor3f(*CONFLICT_COLOUR) bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glVertex2f(s_x1, s_y1) bgl.glVertex2f(s_x2, s_y1) bgl.glVertex2f(s_x2, s_y2) bgl.glVertex2f(s_x1, s_y2) bgl.glEnd() bgl.glPopAttrib()
def draw_lines(self, args): self, context = args # draw confirmed lines bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(self.thickness) bgl.glColor4f(*colorcodes[self.color], self.alpha) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in self.mouse_coords: bgl.glVertex2i(int(x), int(y)) bgl.glEnd() # draw preview line if self.mouse_coords: # see https://blender.stackexchange.com/a/21526/33919 bgl.glPushAttrib(bgl.GL_ENABLE_BIT) bgl.glLineStipple(1, 0x9999) bgl.glEnable(bgl.GL_LINE_STIPPLE) # 50% alpha, 2 pixel width line bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(*colorcodes[self.color], 0.4) bgl.glLineWidth(self.thickness) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in [ self.mouse_coords[-1], mathutils.Vector((self.mouse_x, self.mouse_y)) ]: bgl.glVertex2i(int(x), int(y)) bgl.glEnd() bgl.glPopAttrib() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS) FONT_RGBA = (0.8, 0.1, 0.1, 0.5) bgl.glColor4f(*FONT_RGBA) font_size = 11 DPI = 72 blf.size(0, font_size, DPI) msg = "Head Camera on..." msg_w,msg_h = blf.dimensions(0, msg) pos_x = context.region.width - msg_w pos_y = font_size / 2 blf.position(0, pos_x, pos_y, 0) #blf.position(0, 10, 10, 0) blf.draw(0, msg) bgl.glPopAttrib() pass
def draw_callback_postpixel(self, context): bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # save OpenGL attributes self.draw_postpixel(context) bgl.glPopAttrib() # restore OpenGL attributes
def pop(self): """push()時の状態に戻す。""" self._load_matrix(self._modelview_stack.pop(), self._projection_stack.pop()) bgl.glPopAttrib()
def status_image(): """ Show the corrensponding Image for the status """ imageHeight = windowHeight * 0.075 imageWidth = imageHeight x = windowWidth * 0.35 - imageWidth/2 y = windowHeight * 0.45 - imageHeight/2 gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]] cam = logic.getCurrentScene().active_camera # get the suffix of the human to reference the right objects suffix = cam.name[-4:] if cam.name[-4] == "." else "" hand = objects['Hand_Grab.R' + suffix] # select the right Image if hand["selected"]: tex_id = closed_id else: tex_id = open_id view_buf = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf) view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list # Save the state bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS) # Disable depth test so we always draw over things bgl.glDisable(bgl.GL_DEPTH_TEST) # Disable lighting so everything is shadless bgl.glDisable(bgl.GL_LIGHTING) # Unbinding the texture prevents BGUI frames from somehow picking up on # color of the last used texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) # Make sure we're using smooth shading instead of flat bgl.glShadeModel(bgl.GL_SMOOTH) # Setup the matrices bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.gluOrtho2D(0, view[2], 0, view[3]) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glEnable(bgl.GL_TEXTURE_2D) # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) # Bind the texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex_id) # Draw the textured quad bgl.glColor4f(1, 1, 1, 1) bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL) bgl.glPolygonOffset(1.0, 1.0) bgl.glBegin(bgl.GL_QUADS) for i in range(4): bgl.glTexCoord2f(texco[i][0], texco[i][1]) bgl.glVertex2f(gl_position[i][0], gl_position[i][1]) bgl.glEnd() bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glPopAttrib()