Python bgl.glColor3f() Examples

The following are 10 code examples of bgl.glColor3f(). 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: 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 #2
Source File: ops.py    From Screencast-Keys with GNU General Public License v3.0 5 votes vote down vote up
def draw_rect(x1, y1, x2, y2, color):
    bgl.glColor3f(*color)

    bgl.glBegin(bgl.GL_QUADS)
    bgl.glVertex2f(x1, y1)
    bgl.glVertex2f(x1, y2)
    bgl.glVertex2f(x2, y2)
    bgl.glVertex2f(x2, y1)
    bgl.glEnd()

    bgl.glColor3f(1.0, 1.0, 1.0) 
Example #3
Source File: space_view3d_game_props_visualiser.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def draw_callback(self, context):
    # polling
    if context.mode == 'EDIT_MESH':
        return

    """
    # retrieving ID property data
    try:
        texts = context.scene['GamePropsVisualizer']
    except:
        return

    if not texts:
        return
    """

    texts = context.scene['GamePropsVisualizer']

    # draw
    i = 0

    blf.size(0, 12, 72)


    bgl.glColor3f(1.0, 1.0, 1.0)
    for ob in bpy.context.selected_objects:
        for pi,p in enumerate(ob.game.properties):
            blf.position(0, texts[i], texts[i+1] - (pi+1) * 14, 0)
            if p.type=='FLOAT':
                t=p.name+':  '+ str('%g' % p.value)
            else:
                t=p.name+':  '+ str(p.value)
            blf.draw(0, t)
            i += 2


# operator 
Example #4
Source File: bmesh_render.py    From addon_common with GNU General Public License v3.0 5 votes vote down vote up
def glColor(color):
    if len(color) == 3:
        bgl.glColor3f(*color)
    else:
        bgl.glColor4f(*color) 
Example #5
Source File: ogl_velocitiesrenderer.py    From BAddons with GNU General Public License v3.0 5 votes vote down vote up
def drawCallback(self):
        mat = self.interfacer.getBlenderObject().matrix_world
        if self.do_draw and self.interfacer.isClean():
            # isClean() is not really needed here, but it shows its
            # behavior and helps reducing (a tiny bit!) the run time...
            bgl.glColor3f(0.0, 1.0, 1.0)
            bgl.glPointSize(5)
            bgl.glBegin(bgl.GL_POINTS)
            for v in self.vertices:
                bgl.glVertex3f(*(mat*v))
            bgl.glEnd()
            bgl.glPointSize(1)

            bgl.glColor3f(1.0, 1.0, 0.0)
            bgl.glLineWidth(2)
            bgl.glBegin(bgl.GL_LINES)
            for v, w in zip(self.vertices, self.velocities):
                bgl.glVertex3f(*(mat*v))
                bgl.glVertex3f(*(mat*(v + w)))
            bgl.glEnd()
            bgl.glLineWidth(1)


# this in toplevel is also requested
# MAIN_CLASS should be set to any callable returning the
# requested instance, which provides the update() method. 
Example #6
Source File: 3dview_play_tictactoe.py    From BAddons with GNU General Public License v3.0 5 votes vote down vote up
def drawO(self, xa, xb, ya, yb):
        bgl.glColor3f(*self.COLOR_O)
        r = xb - xa
        bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0)
        bgl.glVertex3f((xa + xb)/2.0, yb - r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f((xa + xb)/2.0, yb - r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0)
        bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0)
        bgl.glVertex3f((xa + xb)/2.0, ya + r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f((xa + xb)/2.0, ya + r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0) 
Example #7
Source File: 3dview_play_tictactoe.py    From BAddons with GNU General Public License v3.0 5 votes vote down vote up
def drawX(self, xa, xb, ya, yb):
        bgl.glColor3f(*self.COLOR_X)
        r = xb - xa
        bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, ya + r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, yb - r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, yb - r*self.EMPTY_FACTOR, 0.0)
        bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, ya + r*self.EMPTY_FACTOR, 0.0) 
Example #8
Source File: node_colorramp_dropper.py    From BAddons with GNU General Public License v3.0 5 votes vote down vote up
def drawPoint(x, y, main=True):
        r = 6 if main else 3

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor3f(1.0, 1.0, 1.0)
        bgl.glVertex2i(x - r, y)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x, y + r)
        
        bgl.glVertex2i(x + r, y)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x, y - r)
        
        bgl.glColor3f(0.0, 0.0, 0.0)
        bgl.glVertex2i(x, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y)
        
        bgl.glVertex2i(x, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y)
        bgl.glEnd() 
Example #9
Source File: ops.py    From Screencast-Keys with GNU General Public License v3.0 4 votes vote down vote up
def draw_rounded_box(x, y, w, h, round_radius, fill=False, color=[1.0, 1.0, 1.0],
                     round_corner=[True, True, True, True]):
    """round_corner: [Right Bottom, Left Bottom, Right Top, Left Top]"""

    def circle_verts_num(r):
        """Get number of verticies for circle optimized for drawing."""

        num_verts = 32
        threshold = 2.0  # pixcel
        while True:
            if r * 2 * math.pi / num_verts > threshold:
                return num_verts
            num_verts -= 4
            if num_verts < 1:
                return 1

    num_verts = circle_verts_num(round_radius)
    n = int(num_verts / 4) + 1
    dangle = math.pi * 2 / num_verts

    radius = [round_radius if rc else 0 for rc in round_corner]

    x_origin = [
        x + radius[0],
        x + w - radius[1],
        x + w - radius[2],
        x + radius[3],
    ]
    y_origin = [
        y + radius[0],
        y + radius[1],
        y + h - radius[2],
        y + h - radius[3],
    ]
    angle_start = [
        math.pi * 1.0,
        math.pi * 1.5,
        math.pi * 0.0,
        math.pi * 0.5,
    ]

    bgl.glColor3f(*color)
    if fill:
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    else:
        bgl.glBegin(bgl.GL_LINE_LOOP)
    for x0, y0, angle, r in zip(x_origin, y_origin, angle_start, radius):
        for _ in range(n):
            x = x0 + r * math.cos(angle)
            y = y0 + r * math.sin(angle)
            bgl.glVertex2f(x, y)
            angle += dangle
    bgl.glEnd()
    bgl.glColor3f(1.0, 1.0, 1.0) 
Example #10
Source File: mesh_show_vgroup_weights.py    From Fluid-Designer with GNU General Public License v3.0 4 votes vote down vote up
def draw_callback(self, context):
    # polling
    if context.mode != "EDIT_MESH" or len(context.active_object.vertex_groups) == 0:
        return
    # retrieving ID property data
    try:
        texts = context.active_object.data["show_vgroup_verts"]
        weights = context.active_object.data["show_vgroup_weights"]
    except:
        return
    if not texts:
        return

    bm = bmesh.from_edit_mesh(context.active_object.data)

    if bm.select_mode == {'VERT'} and bm.select_history.active is not None:
        active_vert = bm.select_history.active
    else:
        active_vert = None

    # draw
    blf.size(0, 13, 72)
    blf.enable(0, blf.SHADOW)
    blf.shadow(0, 3, 0.0, 0.0, 0.0, 1.0)
    blf.shadow_offset(0, 2, -2)
    for i in range(0, len(texts), 7):
        bgl.glColor3f(texts[i], texts[i+1], texts[i+2])
        blf.position(0, texts[i+4], texts[i+5], texts[i+6])
        blf.draw(0, "Vertex " + str(int(texts[i+3])) + ":")
        font_y = texts[i+5]
        group_name = ""
        for j in range(0, len(weights), 3):
            if int(weights[j]) == int(texts[i+3]):
                font_y -= 13
                blf.position(0, texts[i+4] + 10, font_y, texts[i+6])
                for group in context.active_object.vertex_groups:
                    if group.index == int(weights[j+1]):
                        group_name = group.name
                        break
                blf.draw(0, group_name + ": %.3f" % weights[j+2])
        if group_name == "":
            font_y -= 13
            blf.position(0, texts[i+4] + 10, font_y, texts[i+6])
            blf.draw(0, "No Groups")

    # restore defaults
    blf.disable(0, blf.SHADOW)


# operator