示例#1
0
    def draw_texture(cls, _, context):
        sc = context.scene

        if not cls.is_running(context):
            return

        # no textures are selected
        if sc.muv_texture_projection_tex_image == "None":
            return

        # get texture to be renderred
        img = bpy.data.images[sc.muv_texture_projection_tex_image]

        # setup rendering region
        rect = _get_canvas(context, sc.muv_texture_projection_tex_magnitude)
        positions = [
            [rect.x0, rect.y0],
            [rect.x0, rect.y1],
            [rect.x1, rect.y1],
            [rect.x1, rect.y0]
        ]
        tex_coords = [
            [0.0, 0.0],
            [0.0, 1.0],
            [1.0, 1.0],
            [1.0, 0.0]
        ]

        # OpenGL configuration
        if compat.check_version(2, 80, 0) >= 0:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glActiveTexture(bgl.GL_TEXTURE0)
            if img.bindcode:
                bind = img.bindcode
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
        else:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            if img.bindcode:
                bind = img.bindcode[0]
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
                bgl.glTexEnvi(
                    bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                    bgl.GL_MODULATE)

        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0,
                      sc.muv_texture_projection_tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
    def draw_texture(cls, _, context):
        sc = context.scene

        if not cls.is_running(context):
            return

        # no textures are selected
        if sc.muv_texture_projection_tex_image == "None":
            return

        # get texture to be renderred
        img = bpy.data.images[sc.muv_texture_projection_tex_image]

        # setup rendering region
        rect = _get_canvas(context, sc.muv_texture_projection_tex_magnitude)
        positions = [
            [rect.x0, rect.y0],
            [rect.x0, rect.y1],
            [rect.x1, rect.y1],
            [rect.x1, rect.y0]
        ]
        tex_coords = [
            [0.0, 0.0],
            [0.0, 1.0],
            [1.0, 1.0],
            [1.0, 0.0]
        ]

        # OpenGL configuration
        if compat.check_version(2, 80, 0) >= 0:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glActiveTexture(bgl.GL_TEXTURE0)
            if img.bindcode:
                bind = img.bindcode
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
        else:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            if img.bindcode:
                bind = img.bindcode[0]
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
                bgl.glTexEnvi(
                    bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                    bgl.GL_MODULATE)

        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0,
                      sc.muv_texture_projection_tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
示例#3
0
    def __init__(self, filename):
        from bge import texture

        self.region = None

        if not filename.startswith('/'):
            f = inspect.getframeinfo(inspect.currentframe()).filename
            d = os.path.dirname(f)

            filename = os.path.join(d, 'data', filename)

        m = Texture.atlas.match(filename)

        self.filename = filename

        if not m is None:
            self.setup_atlas(m.group(1), m.group(2))
        else:
            self.source = texture.ImageFFmpeg(self.filename)
            self.buffer = texture.imageToArray(self.source, 'RGBA')

            if self.buffer is None:
                print('Error loading {0}: {1}'.format(filename,
                                                      texture.getLastError()))

            self.glid = bgl.Buffer(bgl.GL_INT, 1)
            bgl.glGenTextures(1, self.glid)

            self.bind()

            bgl.glTexEnvi(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                          bgl.GL_REPLACE)
            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.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, self.width,
                             self.height, 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE,
                             self.buffer)

            self.unbind()
    def draw_texture(self, context):
        wm = context.window_manager
        sc = context.scene
        
        # no texture is selected
        if sc.tex_image == "None":
            return

        # setup rendering region
        rect = get_canvas(context, sc.tex_magnitude)
        positions = [
            [rect.x0, rect.y0],
            [rect.x0, rect.y1],
            [rect.x1, rect.y1],
            [rect.x1, rect.y0]
            ]
        tex_coords = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]

        # get texture to be renderred
        img = bpy.data.images[sc.tex_image]

        # OpenGL configuration
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        if img.bindcode:
            bind = img.bindcode
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
            bgl.glTexParameteri(
                bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
            bgl.glTexParameteri(
                bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
            bgl.glTexEnvi(
                bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE)
        
        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0, sc.tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
    def draw_texture(self, context):
        wm = context.window_manager
        sc = context.scene

        # no texture is selected
        if sc.tex_image == "None":
            return

        # setup rendering region
        rect = get_canvas(context, sc.tex_magnitude)
        positions = [[rect.x0, rect.y0], [rect.x0, rect.y1],
                     [rect.x1, rect.y1], [rect.x1, rect.y0]]
        tex_coords = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]

        # get texture to be renderred
        img = bpy.data.images[sc.tex_image]

        # OpenGL configuration
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        if img.bindcode:
            bind = img.bindcode
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
            bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                                bgl.GL_LINEAR)
            bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                                bgl.GL_LINEAR)
            bgl.glTexEnvi(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                          bgl.GL_MODULATE)

        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0, sc.tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
示例#6
0
    def draw_texture(cls, _, context):
        sc = context.scene

        if not cls.is_running(context):
            return

        # no textures are selected
        if sc.muv_texture_projection_tex_image == "None":
            return

        # get texture to be renderred
        img = bpy.data.images[sc.muv_texture_projection_tex_image]

        # setup rendering region
        rect = _get_canvas(context)

        # Apply affine transformation.
        center = mathutils.Vector((
            (rect.x1 + rect.x0) / 2.0,
            (rect.y1 + rect.y0) / 2.0,
            0.0,
        ))
        p1 = mathutils.Vector((rect.x0 - center.x, rect.y0 - center.y, 1.0))
        p2 = mathutils.Vector((rect.x0 - center.x, rect.y1 - center.y, 1.0))
        p3 = mathutils.Vector((rect.x1 - center.x, rect.y1 - center.y, 1.0))
        p4 = mathutils.Vector((rect.x1 - center.x, rect.y0 - center.y, 1.0))
        mat_affine = _create_affine_matrix(
            sc.muv_texture_projection_adjust_window,
            sc.muv_texture_projection_tex_scaling,
            sc.muv_texture_projection_tex_rotation,
            sc.muv_texture_projection_tex_translation)
        p1 = compat.matmul(mat_affine, p1) + center
        p2 = compat.matmul(mat_affine, p2) + center
        p3 = compat.matmul(mat_affine, p3) + center
        p4 = compat.matmul(mat_affine, p4) + center

        positions = [[p1.x, p1.y], [p2.x, p2.y], [p3.x, p3.y], [p4.x, p4.y]]
        tex_coords = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]

        # OpenGL configuration
        if compat.check_version(2, 80, 0) >= 0:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glActiveTexture(bgl.GL_TEXTURE0)
            if img.bindcode:
                bind = img.bindcode
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
        else:
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            if img.bindcode:
                bind = img.bindcode[0]
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
                bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
                                    bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
                bgl.glTexEnvi(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                              bgl.GL_MODULATE)

        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0,
                      sc.muv_texture_projection_tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()