Python bgl.glBlendFunc() Examples

The following are 4 code examples of bgl.glBlendFunc(). 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: 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 #3
Source File: io_export_paper_model.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def display_islands(self, context):
    # TODO: save the vertex positions and don't recalculate them always?
    ob = context.active_object
    if not ob or ob.type != 'MESH':
        return
    mesh = ob.data
    if not mesh.paper_island_list or mesh.paper_island_index == -1:
        return

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    perspMatrix = context.space_data.region_3d.perspective_matrix
    perspBuff = bgl.Buffer(bgl.GL_FLOAT, (4, 4), perspMatrix.transposed())
    bgl.glLoadMatrixf(perspBuff)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    objectBuff = bgl.Buffer(bgl.GL_FLOAT, (4, 4), ob.matrix_world.transposed())
    bgl.glLoadMatrixf(objectBuff)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(0, -10)  # offset in Zbuffer to remove flicker
    bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
    bgl.glColor4f(1.0, 0.4, 0.0, self.islands_alpha)
    island = mesh.paper_island_list[mesh.paper_island_index]
    for lface in island.faces:
        face = mesh.polygons[lface.id]
        bgl.glBegin(bgl.GL_POLYGON)
        for vertex_id in face.vertices:
            vertex = mesh.vertices[vertex_id]
            bgl.glVertex4f(*vertex.co.to_4d())
        bgl.glEnd()
    bgl.glPolygonOffset(0.0, 0.0)
    bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glLoadIdentity() 
Example #4
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)