Python bgl.glDisable() Examples

The following are 30 code examples of bgl.glDisable(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bgl , or try the search function .
Example #1
Source File: core.py    From BlenderTools with GNU General Public License v2.0 6 votes vote down vote up
def draw_custom_3d_elements(mode):
    """Draws custom 3D elements filled in buffers (if local view is active, then buffers are refilled also).

    :param mode: drawing mode for custom 3D elements (can be: 'Normal' or 'X-ray')
    :type mode: str
    """
    # if empties are disabled in this viewport ... our locators and connections should be too
    if not bpy.context.space_data.show_object_viewport_empty:
        return

    if mode == "Normal":
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

    # draw buffers
    _primitive.draw_buffers(bpy.context.space_data)

    if mode == "Normal":
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        bgl.glDisable(bgl.GL_BLEND) 
Example #2
Source File: mi_curve_stretch.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_text_2d(self, context):

    cur_stretch_settings = context.scene.mi_cur_stretch_settings
    rh = context.region.height
    rw = context.region.width

    font_id = 0
    font_size = 30

    #Set font color
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glColor(1, 0.75, 0.1, 1)
    blf.color(0, 1, 0.75, 0.1, 1)
    bgl.glLineWidth(2)

    #Draw text
    blf.position(font_id, rw - 400, 210 - font_size, 0)
    blf.size(font_id, font_size, 72)
    blf.draw(font_id, str(cur_stretch_settings.points_number))

    # restore opengl defaults
    bgl.glLineWidth(1)
    blf.color(0, 0.0, 0.0, 0.0, 1.0)
    bgl.glDisable(bgl.GL_BLEND)
    #bgl.glColor(0, 0.0, 0.0, 0.0, 1.0) 
Example #3
Source File: operator_modal_draw.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def draw_callback_px(self, context):
    print("mouse points", len(self.mouse_path))

    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #4
Source File: space_view3d_enhanced_3d_cursor.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def draw_callback_px(self, context):
    global cursor_save_location
    settings = find_settings()
    if settings is None:
        return
    library = settings.libraries.get_item()

    tfm_operator = CursorDynamicSettings.active_transform_operator

    if settings.show_bookmarks and library:
        library.draw_bookmark(context)

    if tfm_operator:
        tfm_operator.draw_2d(context)

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)


# ===== UTILITY FUNCTIONS ===== # 
Example #5
Source File: ops.py    From Screencast-Keys with GNU General Public License v3.0 6 votes vote down vote up
def draw_line(p1, p2, color, shadow=False, shadow_color=None):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_SMOOTH)

    # Draw shadow.
    if shadow:
        bgl.glLineWidth(3.0)
        bgl.glColor4f(*shadow_color, 1.0)
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(*p1)
        bgl.glVertex2f(*p2)
        bgl.glEnd()

    # Draw line.
    bgl.glLineWidth(1.5 if shadow else 1.0)
    bgl.glColor3f(*color)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(*p1)
    bgl.glVertex2f(*p2)
    bgl.glEnd()

    bgl.glLineWidth(1.0)
    bgl.glDisable(bgl.GL_LINE_SMOOTH) 
Example #6
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 6 votes vote down vote up
def draw(self, engine, context, scene):
        if self._transparent:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA)

        engine.bind_display_space_shader(scene)

        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture_id)
        bgl.glBindVertexArray(self.vertex_array[0])
        bgl.glDrawArrays(bgl.GL_TRIANGLE_FAN, 0, 4)
        bgl.glBindVertexArray(NULL)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, NULL)

        engine.unbind_display_space_shader()

        err = bgl.glGetError()
        if err != bgl.GL_NO_ERROR:
            print("GL Error:", err)

        if self._transparent:
            bgl.glDisable(bgl.GL_BLEND) 
Example #7
Source File: viewport.py    From BlendLuxCore with GNU General Public License v3.0 6 votes vote down vote up
def draw_image(x, y, width, height, image, transparency, crop=(0, 0, 1, 1)):
    # draw_rect(x,y, width, height, (.5,0,0,.5))

    coords = [
        (x, y), (x + width, y),
        (x, y + height), (x + width, y + height)]

    uvs = [(crop[0], crop[1]),
           (crop[2], crop[1]),
           (crop[0], crop[3]),
           (crop[2], crop[3]),
           ]

    indices = [(0, 1, 2), (2, 1, 3)]

    shader = gpu.shader.from_builtin('2D_IMAGE')
    batch = batch_for_shader(shader, 'TRIS',
                             {"pos": coords,
                              "texCoord": uvs},
                             indices=indices)

    # send image to gpu if it isn't there already
    if image.gl_load():
        raise Exception()

    # texture identifier on gpu
    texture_id = image.bindcode

    # in case someone disabled it before
    bgl.glEnable(bgl.GL_BLEND)

    # bind texture to image unit 0
    bgl.glActiveTexture(bgl.GL_TEXTURE0)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture_id)

    shader.bind()
    # tell shader to use the image that is bound to image unit 0
    shader.uniform_int("image", 0)
    batch.draw(shader)

    bgl.glDisable(bgl.GL_TEXTURE_2D) 
Example #8
Source File: operator_modal_draw.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def draw_callback_px(self, context):
    print("mouse points", len(self.mouse_path))

    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #9
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mi_curve_draw_3d_polyline(points, p_size, p_col, x_ray):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    if x_ray is True:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
 #   bgl.glBegin(bgl.GL_POLYGON)

    for point in points:
        bgl.glVertex3f(point[0], point[1], point[2])

    if x_ray is True:
        bgl.glEnable(bgl.GL_DEPTH_TEST)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #10
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mi_draw_2d_point(point_x, point_y, p_size=4, p_col=(1.0,1.0,1.0,1.0)):
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    #bgl.glLineWidth(2)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_POINTS)
 #   bgl.glBegin(bgl.GL_POLYGON)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
    bgl.glVertex2f(point_x, point_y)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)


# TODO MOVE TO UTILITIES 
Example #11
Source File: skeleton_ui_draw.py    From object_alignment with GNU General Public License v3.0 6 votes vote down vote up
def draw3d_polyline(points, color, thickness, view_loc, view_ortho, stipple=False, zfar=0.997):
    if not points: return
    if stipple:
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    set_depthrange(0.0, zfar, points, view_loc, view_ortho)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
    bgl.glLineWidth(1)
    if stipple:
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines 
Example #12
Source File: image_background_transform.py    From image-background-transform with GNU General Public License v2.0 6 votes vote down vote up
def draw_callback_px(self, context):
    """From blender's operator_modal_draw.py modal operator template"""
    if self.do_draw:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        bgl.glLineWidth(1)

        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2i(int(self.draw_start.x), int(self.draw_start.y))
        bgl.glVertex2i(int(self.draw_end.x), int(self.draw_end.y))

        bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #13
Source File: mi_widget_curve.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_3d_polyline(points, p_size, p_col, x_ray):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    if x_ray is True:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
 #   bgl.glBegin(bgl.GL_POLYGON)

    for point in points:
        bgl.glVertex3f(point[0], point[1], point[2])

    if x_ray is True:
        bgl.glEnable(bgl.GL_DEPTH_TEST)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #14
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mi_curve_draw_3d_polyline(points, p_size, p_col, x_ray):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    if x_ray is True:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
 #   bgl.glBegin(bgl.GL_POLYGON)

    for point in points:
        bgl.glVertex3f(point[0], point[1], point[2])

    if x_ray is True:
        bgl.glEnable(bgl.GL_DEPTH_TEST)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #15
Source File: ui.py    From addon_common with GNU General Public License v3.0 6 votes vote down vote up
def draw_darken(self):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()
        bgl.glColor4f(0,0,0,0.25)    # 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() 
Example #16
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mi_draw_2d_point(point_x, point_y, p_size=4, p_col=(1.0,1.0,1.0,1.0)):
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    #bgl.glLineWidth(2)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_POINTS)
 #   bgl.glBegin(bgl.GL_POLYGON)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
    bgl.glVertex2f(point_x, point_y)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)


# TODO MOVE TO UTILITIES 
Example #17
Source File: display.py    From phobos with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def draw_callback_3d(self, context):
    """Callback function for 3d drawing.

    Args:
      context: 

    Returns:

    """
    active = context.object
    selected = context.selected_objects
    wm = context.window_manager

    bgl.glEnable(bgl.GL_BLEND)

    # joint axes
    if len(selected) > 0:
        if wm.draw_jointaxes:
            for j in [o for o in selected if o.phobostype == 'link']:
                draw_joint(j, wm.jointaxes_length)

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #18
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_callback_px_3d(self, context):

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(2)

   # bgl.glBegin(bgl.GL_LINE_STRIP)
   # bgl.glVertex3f(*ob.matrix_world.translation)
   # bgl.glVertex3f(*context.scene.cursor_location)
   # bgl.glEnd()

    bgl.glBegin(bgl.GL_POLYGON)
    #bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glVertex3f(0.0, 0.0, 0.0)
    bgl.glVertex3f(0.0, 1.0, 0.0)
    bgl.glVertex3f(1.0, 1.0, 0.0)
    bgl.glVertex3f(1.0, 0.0, 0.0)
    bgl.glEnd()

    ##bgl.glEnable(bgl.GL_BLEND)
    ##bgl.glLineWidth(1.5)
    #bgl.glPointSize(4)
##    bgl.glBegin(bgl.GL_LINE_LOOP)
    #bgl.glBegin(bgl.GL_POINTS)
 ##   bgl.glBegin(bgl.GL_POLYGON)
    #bgl.glColor4f(0.5,1.1,1.0,0.5)
    #bgl.glVertex2f(10, 20)
    #bgl.glVertex2f(50,60)
    #bgl.glVertex2f(700,80)
    #bgl.glVertex2f(2,180)
    #bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #19
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 5 votes vote down vote up
def draw(self, context, render=False):
        if self.image is None:
            return
        bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
        p0 = self.pts[0]
        p1 = self.pts[1]
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(*self.colour)
        bgl.glRectf(p0.x, p0.y, p1.x, p1.y)
        self.image.gl_load()
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.image.bindcode[0])
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
        # bgl.glColor4f(1, 1, 1, 1)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2d(0, 0)
        bgl.glVertex2d(p0.x, p0.y)
        bgl.glTexCoord2d(0, 1)
        bgl.glVertex2d(p0.x, p1.y)
        bgl.glTexCoord2d(1, 1)
        bgl.glVertex2d(p1.x, p1.y)
        bgl.glTexCoord2d(1, 0)
        bgl.glVertex2d(p1.x, p0.y)
        bgl.glEnd()
        self.image.gl_free()
        bgl.glDisable(bgl.GL_TEXTURE_2D) 
Example #20
Source File: display.py    From phobos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_2dpolygon(points, linecolor=None, fillcolor=None, distance=0.2, linewidth=1):
    """

    Args:
      points: 
      linecolor: (Default value = None)
      fillcolor: (Default value = None)
      distance: (Default value = 0.2)
      linewidth: (Default value = 1)

    Returns:

    """
    # background
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(linewidth)
    if fillcolor:
        bgl.glColor4f(*fillcolor)
        bgl.glBegin(bgl.GL_POLYGON)
        for p in points:
            bgl.glVertex3f(*p, distance)
        bgl.glEnd()
    # frame
    if linecolor:
        bgl.glColor4f(*linecolor)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for p in points:
            bgl.glVertex3f(*p, distance)
        bgl.glVertex3f(*points[0], distance)
        bgl.glEnd()
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND) 
Example #21
Source File: mi_widget_select.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_circle_select(m_coords, radius = 16, p_col = (0.7,0.8,1.0,0.6), enabled = False, sub = False):
    if(enabled):
        f_col = p_col
        if sub:
            f_col = (1.0, 0.5, 0.4, 0.6)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_POLYGON)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]/3)

        point_x = m_coords[0]
        point_y = m_coords[1]

        radius = int(radius)

        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360/(radius*2)) / 180 * 3.14159), point_y + radius * math.sin(x * (360/(radius*2)) / 180 * 3.14159))
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3])
        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360 / (radius * 2)) / 180 * 3.14159),
                           point_y + radius * math.sin(x * (360 / (radius * 2)) / 180 * 3.14159))

        bgl.glEnd()
        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #22
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_callback_px_2d(self, context):

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(2)

   # bgl.glBegin(bgl.GL_LINE_STRIP)
   # bgl.glVertex3f(*ob.matrix_world.translation)
   # bgl.glVertex3f(*context.scene.cursor_location)
   # bgl.glEnd()

    #bgl.glBegin(bgl.GL_POLYGON)
    ##bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    #bgl.glVertex3f(0.0, 0.0, 0.0)
    #bgl.glVertex3f(0.0, 1.0, 0.0)
    #bgl.glVertex3f(1.0, 1.0, 0.0)
    #bgl.glVertex3f(1.0, 0.0, 0.0)
    #bgl.glEnd()

    #bgl.glEnable(bgl.GL_BLEND)
    #bgl.glLineWidth(1.5)
    bgl.glPointSize(4)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_POINTS)
 #   bgl.glBegin(bgl.GL_POLYGON)
    bgl.glColor4f(0.5,1.1,1.0,0.5)
    bgl.glVertex2f(10, 20)
    bgl.glVertex2f(50,60)
    bgl.glVertex2f(700,80)
    bgl.glVertex2f(2,180)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #23
Source File: skeleton_ui_draw.py    From object_alignment with GNU General Public License v3.0 5 votes vote down vote up
def draw2d_polyline(points, color, thickness, stipple=False):
    if stipple:
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points: bgl.glVertex2f(*coord)
    bgl.glEnd()
    bgl.glLineWidth(1)
    if stipple:
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines 
Example #24
Source File: mi_widget_curve.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_3d_polyline(points, p_size, p_col, x_ray):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    if x_ray is True:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glPointSize(p_size)

    coords = [(point[0], point[1], point[2]) for point in points]
    batch = batch_for_shader(shader3d, 'LINE_STRIP', {"pos": coords})
    shader3d.bind()
    shader3d.uniform_float("color", (p_col[0], p_col[1], p_col[2], p_col[3]))
    batch.draw(shader3d)

    # bgl.glBegin(bgl.GL_LINE_STRIP)
    # bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
    # for point in points:
    #     bgl.glVertex3f(point[0], point[1], point[2])

    if x_ray is True:
        bgl.glEnable(bgl.GL_DEPTH_TEST)

    # bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND) 
Example #25
Source File: mi_widget_select.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_circle_select(m_coords, radius = 16, p_col = (0.7,0.8,1.0,0.6), enabled = False, sub = False):
    if(enabled):
        f_col = p_col

        if sub:
            f_col = (1.0, 0.5, 0.4, 0.6)

        bgl.glEnable(bgl.GL_BLEND)

        radius = int(radius)

        presets.draw_circle_2d(m_coords, (f_col[0], f_col[1], f_col[2], f_col[3]), radius, segments=64)

        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND) 
Example #26
Source File: archipack_gl.py    From archipack with GNU General Public License v3.0 5 votes vote down vote up
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)
        # print("_end %s" % (type(self).__name__)) 
Example #27
Source File: display.py    From phobos with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_path(path, color=colors['white'], dim3=False, width=4):
    """

    Args:
      path: 
      color: (Default value = colors['white'])
      dim3: (Default value = False)
      width: (Default value = 4)

    Returns:

    """
    origins = []
    for e in range(len(path)):
        origins.append(path[e].matrix_world.to_translation())

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(width)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glColor4f(*color)
    for o in origins:
        if dim3:
            bgl.glVertex3f(o)
        else:
            bgl.glVertex2f(*to2d(o))
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND) 
Example #28
Source File: cm_draw.py    From CrowdMaster with GNU General Public License v3.0 5 votes vote down vote up
def __exit__(self, type, value, traceback):
        bgl.glEnd()
        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #29
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_callback_px_2d(self, context):

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(2)

   # bgl.glBegin(bgl.GL_LINE_STRIP)
   # bgl.glVertex3f(*ob.matrix_world.translation)
   # bgl.glVertex3f(*context.scene.cursor_location)
   # bgl.glEnd()

    #bgl.glBegin(bgl.GL_POLYGON)
    ##bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    #bgl.glVertex3f(0.0, 0.0, 0.0)
    #bgl.glVertex3f(0.0, 1.0, 0.0)
    #bgl.glVertex3f(1.0, 1.0, 0.0)
    #bgl.glVertex3f(1.0, 0.0, 0.0)
    #bgl.glEnd()

    #bgl.glEnable(bgl.GL_BLEND)
    #bgl.glLineWidth(1.5)
    bgl.glPointSize(4)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_POINTS)
 #   bgl.glBegin(bgl.GL_POLYGON)
    bgl.glColor4f(0.5,1.1,1.0,0.5)
    bgl.glVertex2f(10, 20)
    bgl.glVertex2f(50,60)
    bgl.glVertex2f(700,80)
    bgl.glVertex2f(2,180)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 
Example #30
Source File: mi_curve_test.py    From mifthtools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def draw_callback_px_3d(self, context):

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(2)

   # bgl.glBegin(bgl.GL_LINE_STRIP)
   # bgl.glVertex3f(*ob.matrix_world.translation)
   # bgl.glVertex3f(*context.scene.cursor_location)
   # bgl.glEnd()

    bgl.glBegin(bgl.GL_POLYGON)
    #bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glVertex3f(0.0, 0.0, 0.0)
    bgl.glVertex3f(0.0, 1.0, 0.0)
    bgl.glVertex3f(1.0, 1.0, 0.0)
    bgl.glVertex3f(1.0, 0.0, 0.0)
    bgl.glEnd()

    ##bgl.glEnable(bgl.GL_BLEND)
    ##bgl.glLineWidth(1.5)
    #bgl.glPointSize(4)
##    bgl.glBegin(bgl.GL_LINE_LOOP)
    #bgl.glBegin(bgl.GL_POINTS)
 ##   bgl.glBegin(bgl.GL_POLYGON)
    #bgl.glColor4f(0.5,1.1,1.0,0.5)
    #bgl.glVertex2f(10, 20)
    #bgl.glVertex2f(50,60)
    #bgl.glVertex2f(700,80)
    #bgl.glVertex2f(2,180)
    #bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)