示例#1
0
    def __init__(self, path):
        self.worldPosition = [0, 0, 0]
        self.visible = True
        self.path = path
        self.fullpath = logic.expandPath("//../data/" + path)
        self.texture = texture.ImageFFmpeg(self.fullpath)
        self.clipping = None

        self._tex_id = glGenTextures(1)
        self.size = [0, 0]
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                      bgl.GL_MODULATE)

        self.reload()

        self.texco = [(0, 0), (1, 0), (1, 1), (0, 1)]
        self.color = [1, 1, 1, 1]

        x = render.getWindowWidth() / 2
        y = render.getWindowHeight() / 2

        size = [50, 50]

        width = size[0]
        height = size[1]
        self._size = [width, height]

        # The "private" position returned by setter
        self._position = [x, y]
        self._last_position = self._position
        self.calculate_glposition()
        module.scene_gui.post_draw.append(self.draw)
        self.scale = 0.5, 0.5
示例#2
0
    def draw_texture(x=0, y=0, w=30, h=10, texname=texname):
        # function to draw a texture
        bgl.glDisable(bgl.GL_DEPTH_TEST)

        act_tex = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetIntegerv(bgl.GL_TEXTURE_2D, act_tex)

        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                      bgl.GL_REPLACE)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texname)

        texco = [(0, 1), (1, 1), (1, 0), (0, 0)]
        verco = [(x, y), (x + w, y), (x + w, y - h), (x, y - h)]

        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
        bgl.glBegin(bgl.GL_QUADS)
        for i in range(4):
            bgl.glTexCoord3f(texco[i][0], texco[i][1], 0.0)
            bgl.glVertex2f(verco[i][0], verco[i][1])
        bgl.glEnd()

        # restoring settings
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, act_tex[0])
        bgl.glDisable(bgl.GL_TEXTURE_2D)
示例#3
0
    def draw_texture(x=0, y=0, w=30, h=10, texname=texname):
        # function to draw a texture
        bgl.glDisable(bgl.GL_DEPTH_TEST)

        act_tex = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetIntegerv(bgl.GL_TEXTURE_2D, act_tex)

        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texname)

        texco = [(0, 1), (1, 1), (1, 0), (0, 0)]
        verco = [(x, y), (x + w, y), (x + w, y - h), (x, y - h)]

        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
        bgl.glBegin(bgl.GL_QUADS)
        for i in range(4):
            bgl.glTexCoord3f(texco[i][0], texco[i][1], 0.0)
            bgl.glVertex2f(verco[i][0], verco[i][1])
        bgl.glEnd()

        # restoring settings
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, act_tex[0])
        bgl.glDisable(bgl.GL_TEXTURE_2D)
def loadtexture(filepath):
    """ Loads a texture from an image (tga, jpg...any format supported by FFMPEG)
    and returns the texture buffer ID.
    """

    id_buf = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGenTextures(1, id_buf)
    id = id_buf.to_list()[0] if hasattr(id_buf, "to_list") else id_buf.list[0]
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, id)
    image = texture.ImageFFmpeg(filepath)
    if not image.image:
        logger.error("Error when loading " + filepath +
                     ". File not found? Format not "
                     "supported by FFMPEG? (tga, jpg, png do work)")
        return -1
    else:
        im_buf = image.image
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                            bgl.GL_LINEAR)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                            bgl.GL_LINEAR)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                      bgl.GL_MODULATE)
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA, image.size[0],
                         image.size[1], 0, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE,
                         im_buf)
        return id
示例#5
0
	def __init__(self, path):
		self.worldPosition = [0,0,0]
		self.visible = True
		self.path = path
		self.fullpath = logic.expandPath("//../data/" + path)
		self.texture = texture.ImageFFmpeg(self.fullpath)
		self.clipping = None
		
		self._tex_id = glGenTextures(1)
		self.size = [0, 0]
		bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE)
		
		self.reload()
		
		self.texco = [(0, 0), (1, 0), (1, 1), (0, 1)]
		self.color = [1, 1, 1, 1]
		
		x = render.getWindowWidth()/2
		y = render.getWindowHeight()/2
		
		size = [50, 50]
		
		width = size[0]
		height = size[1]
		self._size = [width, height]
		
		# The "private" position returned by setter
		self._position = [x, y]
		self._last_position = self._position
		self.calculate_glposition()
		module.scene_gui.post_draw.append(self.draw)
		self.scale = 0.5, 0.5
示例#6
0
def loadtexture(filepath):
    """ Loads a texture from an image (tga, jpg...any format supported by FFMPEG)
    and returns the texture buffer ID.
    """

    id_buf = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGenTextures(1, id_buf)
    id = id_buf.to_list()[0] if hasattr(id_buf, "to_list") else id_buf.list[0]
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, id)
    image = texture.ImageFFmpeg(filepath)
    if not image.image:
        logger.error(
            "Error when loading " + filepath + ". File not found? Format not "
            "supported by FFMPEG? (tga, jpg, png do work)"
        )
        return -1
    else:
        im_buf = image.image
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE)
        bgl.glTexImage2D(
            bgl.GL_TEXTURE_2D,
            0,
            bgl.GL_RGBA,
            image.size[0],
            image.size[1],
            0,
            bgl.GL_RGBA,
            bgl.GL_UNSIGNED_BYTE,
            im_buf,
        )
        return id
示例#7
0
def draw_callback_mode(self, context):
    # draw mode_title
    mode_title(True, "Object Assembler Mode")
    
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode)
    
    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.glLineWidth(1)

    # draw frame
    for icon in self.menu:
        bgl.glColor3f(0.1, 0.1, 0.1)
        bgl.glRecti(
            icon[2][0],icon[2][1],icon[2][2],icon[2][3]
            )

    # icon zeichnen
    for icon in self.menu:
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glTexEnvf(bgl.GL_TEXTURE_ENV,bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE)

        bgl.glBegin(bgl.GL_QUADS)

        bgl.glTexCoord2f(icon[4][0][0], icon[4][0][1])
        bgl.glVertex2f(icon[1][0], icon[1][1])
        
        bgl.glTexCoord2f(icon[4][1][0], icon[4][1][1])
        bgl.glVertex2f(icon[1][0], icon[1][3])
        
        bgl.glTexCoord2f(icon[4][2][0], icon[4][2][1])
        bgl.glVertex2f(icon[1][2], icon[1][3])

        bgl.glTexCoord2f(icon[4][3][0], icon[4][3][1])
        bgl.glVertex2f(icon[1][2], icon[1][1])

        bgl.glEnd()

        bgl.glDisable(bgl.GL_TEXTURE_2D)

    # draw hover effekt
    for icon in self.menu:
        # mouse hover icon
        if mouse_hover_icon(icon[1], self.mouse):
            bgl.glColor3f(0.4, 0.4, 0.4)
            bgl.glLineWidth(2)
            rect_round_corners(icon[3][0], icon[3][1], icon[3][2], icon[3][3])

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
示例#8
0
 def __init__(self, path, interpolation):
     if not hasattr(logic, "texture_cache"):
         logic.texture_cache = {}
         
     self.id = h_gen_texture()
     self.size = [0, 0]
     self.path = None
     self._interpolation = None
     self._cache = False
     
     self.bind()
     bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_MODULATE)
     self.interpolation = interpolation
     
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_S, bgl.GL_REPEAT)
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_T, bgl.GL_REPEAT)
     
     self.reload(path)
示例#9
0
def draw_callback_mode(self, context):
    settings = context.scene.OASettings
    if self.ctrl and not settings.shift:
        mode_title(context, "Replace")
    bgl.glLineWidth(1)

    tool_shelf_width = get_tool_shelf_width(bpy.context)
    # add the offset-width and offset-height for the first time
    if self.menu_offset['first_iteration']:
        for icon in self.menu:
            # iterate over icon, frame and hover
            for i in (1, 2, 3):
                # iterate over lower left and upper right corner
                for j in (0, 2):
                    icon[i][0 + j] += tool_shelf_width
                    icon[i][1 + j] += bpy.context.region.height
        self.menu_offset['first_iteration'] = False

    # add current offset-region-height and offset-tool-shelf-width
    # when the user altered the size of the 3d-view or toggled region_overlap
    elif any((
            self.menu_offset['width'] != tool_shelf_width,
            self.menu_offset['height'] != bpy.context.region.height,
            self.menu_offset['region_overlap'] != bool(
                bpy.context.user_preferences.system.use_region_overlap),
    )):
        for icon in self.menu:
            # iterate over icon, frame and hover
            for i in (1, 2, 3):
                # iterate over lower left and upper right corner
                for j in (0, 2):
                    icon[i][0 + j] += (tool_shelf_width -
                                       self.menu_offset['width'])
                    icon[i][1 + j] += (bpy.context.region.height -
                                       self.menu_offset['height'])

        self.menu_offset['width'] = tool_shelf_width
        self.menu_offset['height'] = bpy.context.region.height
        self.menu_offset['region_overlap'] = bool(
            bpy.context.user_preferences.system.use_region_overlap)

    # draw frame
    bgl.glColor3f(0.1, 0.1, 0.1)
    for icon in self.menu:
        bgl.glRecti(icon[2][0], icon[2][1], icon[2][2], icon[2][3])

    # draw icons
    if settings.valid_icon_file:
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode)
        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)

        for icon in self.menu:
            bgl.glEnable(bgl.GL_TEXTURE_2D)
            bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                          bgl.GL_REPLACE)

            bgl.glBegin(bgl.GL_QUADS)

            bgl.glTexCoord2f(icon[4][0][0], icon[4][0][1])
            bgl.glVertex2f(icon[1][0], icon[1][1])

            bgl.glTexCoord2f(icon[4][1][0], icon[4][1][1])
            bgl.glVertex2f(icon[1][0], icon[1][3])

            bgl.glTexCoord2f(icon[4][2][0], icon[4][2][1])
            bgl.glVertex2f(icon[1][2], icon[1][3])

            bgl.glTexCoord2f(icon[4][3][0], icon[4][3][1])
            bgl.glVertex2f(icon[1][2], icon[1][1])

            bgl.glEnd()

            bgl.glDisable(bgl.GL_TEXTURE_2D)

    else:
        # draw category and model_id if no icon file is provided
        # draw background
        bgl.glColor3f(0.2, 0.2, 0.2)
        for icon in self.menu:
            bgl.glRecti(icon[2][0] + 2, icon[2][1] + 2, icon[2][2] - 2,
                        icon[2][3] - 2)

        font_id = 0
        bgl.glColor4f(1, 1, 1, 1)
        for icon in self.menu:
            blf.position(font_id, icon[1][0] + 1, icon[1][1] + 8, 0)
            blf.size(font_id, int(settings.menu_icon_display_size / 3), 72)
            blf.draw(
                font_id, "{0: >2}".format(icon[0][1]) + "," +
                "{0: >2}".format(icon[0][2]))

    # draw hover effekt
    for icon in self.menu:
        # mouse hover icon
        if mouse_over_icon(icon[1], self.mouse):
            bgl.glColor3f(0.6, 0.6, 0.6)
            bgl.glLineWidth(2)
            rect_round_corners(icon[3][0], icon[3][1], icon[3][2], icon[3][3])

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