Exemple #1
0
    def renderTexture(texture, x, y, width, height):
        bgl.glEnable(bgl.GL_BLEND)
        #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        texture.gl_load()
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture.bindcode[0])

        bgl.glEnable(bgl.GL_TEXTURE_2D)
        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.glColor4f(1, 1, 1, 1)

        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2d(0, 0)
        bgl.glVertex2d(x, y)
        bgl.glTexCoord2d(0, 1)
        bgl.glVertex2d(x, y + height)
        bgl.glTexCoord2d(1, 1)
        bgl.glVertex2d(x + width, y + height)
        bgl.glTexCoord2d(1, 0)
        bgl.glVertex2d(x + width , y)
        bgl.glEnd()

        texture.gl_free()
Exemple #2
0
    def __exit__(self, type, value, traceback):
        mipmap_state = getattr(self, "_mipmap_state", None)
        if mipmap_state is not None:
            bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_GENERATE_MIPMAP, mipmap_state)

        if self._changed_state:
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._previous_texture)
Exemple #3
0
    def draw_textured(self):
        """ call this draw function only if morphs uses texture """
        if self.texture != None:

            self.texture.gl_load()
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture.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) #GL_LINEAR seems to be used in Blender for background images

            bgl.glEnable(bgl.GL_TEXTURE_2D)

            #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)


            bgl.glColor4f(*self.color)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glTexCoord2d(0,0)
            bgl.glVertex2d(self.get_position().x,self.get_position().y)
            bgl.glTexCoord2d(0,1)
            bgl.glVertex2d(self.get_position().x,self.get_position().y+self.get_height())
            bgl.glTexCoord2d(1,1)
            bgl.glVertex2d(self.get_position().x+self.get_width(),self.get_position().y+self.get_height())
            bgl.glTexCoord2d(1,0)
            bgl.glVertex2d(self.get_position().x+self.get_width(),self.get_position().y)
            bgl.glEnd()
            bgl.glDisable(bgl.GL_BLEND)
            bgl.glDisable(bgl.GL_TEXTURE_2D)
            self.texture.gl_free()

        return
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
 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)
    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()
Exemple #7
0
    def generate_mipmap(self):
        """Generates all mip levels for this texture"""
        self._mipmap_state = self._get_tex_param(bgl.GL_GENERATE_MIPMAP)

        # Note that this is a very old feature from OpenGL 1.x -- it's new enough that Windows (and
        # Blender apparently) don't support it natively and yet old enough that it was thrown away
        # in OpenGL 3.0. The new way is glGenerateMipmap, but Blender likes oldgl, so we don't have that
        # function available to us in BGL. I don't want to deal with loading the GL dll in ctypes on
        # many platforms right now (or context headaches). If someone wants to fix this, be my guest!
        # It will simplify our state tracking a bit.
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_GENERATE_MIPMAP, 1)
Exemple #8
0
def gen_texture():
    textures = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGenTextures(1, textures)
    tex = textures[0]
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex)
    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.glBindTexture(bgl.GL_TEXTURE_2D, 0)
    return tex
Exemple #9
0
def drawMenuItem(item, x, y, width, height):
    global iconWidth
    global iconHeight

    iconMarginX = 4
    iconMarginY = 4
    textMarginX = 6

    textHeight = 16
    textWidth = 72

    bgl.glEnable(bgl.GL_BLEND)
    if item["highlighted"]:
        bgl.glColor4f(0.555, 0.555, 0.555, 0.8)
    else:
        bgl.glColor4f(0.447, 0.447, 0.447, 0.8)

    bgl.glRectf(x, y, x + width, y + height)

    texture = item["icon"]
    texture.gl_load()
    bgl.glColor4f(0.0, 0.0, 1.0, 0.5)
    # bgl.glLineWidth(1.5)

    # ------ TEXTURE ---------#
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture.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
    )  # GL_LINEAR seems to be used in Blender for background images
    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(x + iconMarginX, y)
    bgl.glTexCoord2d(0, 1)
    bgl.glVertex2d(x + iconMarginX, y + iconHeight)
    bgl.glTexCoord2d(1, 1)
    bgl.glVertex2d(x + iconMarginX + iconWidth, y + iconHeight)
    bgl.glTexCoord2d(1, 0)
    bgl.glVertex2d(x + iconMarginX + iconWidth, y)
    bgl.glEnd()

    texture.gl_free()

    # draw some text
    font_id = 0
    blf.position(font_id, x + iconMarginX + iconWidth + textMarginX, y + iconHeight * 0.5 - 0.25 * textHeight, 0)
    blf.size(font_id, textHeight, textWidth)
    blf.draw(font_id, item["text"])
    def __init__(self, dimensions):
        # Generate dummy float image buffer
        self.dimensions = dimensions
        width, height = dimensions

        pixels = [0.1, 0.2, 0.1, 1.0] * width * height
        pixels = bgl.Buffer(bgl.GL_FLOAT, width * height * 4, pixels)

        # Generate texture
        self.texture = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGenTextures(1, self.texture)
        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.texture[0])
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA16F, width, height, 0, bgl.GL_RGBA, bgl.GL_FLOAT, pixels)
        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.glBindTexture(bgl.GL_TEXTURE_2D, 0)

        # Bind shader that converts from scene linear to display space,
        # use the scene's color management settings.
        shader_program = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetIntegerv(bgl.GL_CURRENT_PROGRAM, shader_program);

        # Generate vertex array
        self.vertex_array = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGenVertexArrays(1, self.vertex_array)
        bgl.glBindVertexArray(self.vertex_array[0])

        texturecoord_location = bgl.glGetAttribLocation(shader_program[0], "texCoord");
        position_location = bgl.glGetAttribLocation(shader_program[0], "pos");

        bgl.glEnableVertexAttribArray(texturecoord_location);
        bgl.glEnableVertexAttribArray(position_location);

        # Generate geometry buffers for drawing textured quad
        position = [0.0, 0.0, width, 0.0, width, height, 0.0, height]
        position = bgl.Buffer(bgl.GL_FLOAT, len(position), position)
        texcoord = [0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0]
        texcoord = bgl.Buffer(bgl.GL_FLOAT, len(texcoord), texcoord)

        self.vertex_buffer = bgl.Buffer(bgl.GL_INT, 2)

        bgl.glGenBuffers(2, self.vertex_buffer)
        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vertex_buffer[0])
        bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 32, position, bgl.GL_STATIC_DRAW)
        bgl.glVertexAttribPointer(position_location, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0, None)

        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vertex_buffer[1])
        bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 32, texcoord, bgl.GL_STATIC_DRAW)
        bgl.glVertexAttribPointer(texturecoord_location, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0, None)

        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, 0)
        bgl.glBindVertexArray(0)
Exemple #11
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)
Exemple #12
0
    def _config_textures(self):
        import ctypes

        bgl.glBindRenderbuffer(bgl.GL_RENDERBUFFER, self.buf_depth[0])
        bgl.glRenderbufferStorage(
                bgl.GL_RENDERBUFFER, bgl.GL_DEPTH_COMPONENT, self.width, self.height)

        NULL = bgl.Buffer(bgl.GL_INT, 1, (ctypes.c_int32 * 1).from_address(0))
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.buf_color[0])
        bgl.glTexImage2D(
                bgl.GL_TEXTURE_2D, 0, bgl.GL_R32UI, self.width, self.height,
                0, bgl.GL_RED_INTEGER, bgl.GL_UNSIGNED_INT, NULL)
        del NULL

        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)
Exemple #13
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)
Exemple #14
0
	def draw(self):
		if self.visible == False: return
		
		module.post_draw_step += 1
		
		height = render.getWindowHeight()
		width = render.getWindowWidth()
	
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, width, 0, height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
	
		# Enable textures
		bgl.glEnable(bgl.GL_TEXTURE_2D)

		# Enable alpha blending
		bgl.glEnable(bgl.GL_BLEND)
		bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
		bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)

		# Bind the texture
		bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._tex_id)

		# Fix position
		w, h = self._size
		bgl.glTranslatef(0, -h, 1)

		#MipLevel
		bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_BASE_LEVEL, 0);
		bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAX_LEVEL, 0);
		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);
		
		# Draw the textured quad
		bgl.glColor4f(*self.color)

		bgl.glBegin(bgl.GL_QUADS)
		self.calculate_glposition()
		for i in range(4):
			bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1])
			bgl.glVertex2f(self.gl_position[i][0], self.gl_position[i][1])
		bgl.glEnd()

		bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
		
		bgl.glDisable(bgl.GL_BLEND)
		bgl.glDisable(bgl.GL_TEXTURE_2D)

		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPopMatrix()
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
Exemple #15
0
def draw(self,context):

    global iterations
    global texture
    global height
    global width
    texture.gl_load()
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(1.5)

    #------ TEXTURE ---------#

    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture.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) #GL_LINEAR seems to be used in Blender for background images

    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(0 + iterations ,100 )
    bgl.glTexCoord2d(0,1)
    bgl.glVertex2d(0+iterations ,100 + height)
    bgl.glTexCoord2d(1,1)
    bgl.glVertex2d(0 + iterations + width, 100 + height )
    bgl.glTexCoord2d(1,0)
    bgl.glVertex2d(0 + iterations + width , 100)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_TEXTURE_2D)
    texture.gl_free()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    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()
Exemple #17
0
def render_callback(self, context):
    if self.bindcode != None:
        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.glEnable(bgl.GL_BLEND)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.bindcode)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2f(0.0, 0.0)
        bgl.glVertex2f(self.x, self.y)
        bgl.glTexCoord2f(1.0, 0.0)
        bgl.glVertex2f(self.x + self.width, self.y)
        bgl.glTexCoord2f(1.0, 1.0)
        bgl.glVertex2f(self.x + self.width, self.y + self.height)
        bgl.glTexCoord2f(0.0, 1.0)
        bgl.glVertex2f(self.x, self.y + self.height)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_TEXTURE_2D)
Exemple #18
0
 def set_region_data():
     Map.activateBGLcallback(context)
     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)
     Map.object[0].set_dimensions(0)
     Map.toolProps = None
     Map.toolPropsWidth = 0
     for reg in Map.view3d_area.regions:
         if reg.type == 'TOOL_PROPS':
             Map.toolProps = reg
             Map.toolProps_width = reg.width
         elif reg.type == 'WINDOW':
             Map.region = reg
             Map.saved_region_width = reg.width
             Map.object[0].set_dimensions(int(reg.width * .8))
             Map.object[0].origin.x = \
                 int((Map.region.width - Map.object[0].width) / 2)
             Map.object[0].origin.y = 2
     return
def image_quad(img,color,verts):
    img.gl_load(bgl.GL_NEAREST, bgl.GL_NEAREST)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 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.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_QUADS)
    #http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/2025____.HTM
    bgl.glTexCoord2f(0,0)
    bgl.glVertex2f(verts[0][0],verts[0][1])
    bgl.glTexCoord2f(0,1)
    bgl.glVertex2f(verts[1][0],verts[1][1])
    bgl.glTexCoord2f(1,1)
    bgl.glVertex2f(verts[2][0],verts[2][1])
    bgl.glTexCoord2f(1,0)
    bgl.glVertex2f(verts[3][0],verts[3][1])
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_TEXTURE_2D)
    def draw_image(self, image, x, y, w, h, color=(0, 0, 0, 0.1)):
        bgl.glColor4f(0.5, 0.0, 0.5, 0.7)

        # draw main line and handles
        # bgl.glBegin(bgl.GL_LINES)
        bgl.glRectf(x, y, x + w, y + h)
        # bgl.glEnd()
        x1 = x
        y1 = y
        x2 = x + w
        y2 = y + h
        color = [0.5, 0.5, 0.5, 1]

        idx = image.gl_load(bgl.GL_NEAREST, bgl.GL_NEAREST)
        print([i for i in image.bindcode])

        bgl.glBindTexture(bgl.GL_TEXTURE_2D, 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.glEnable(bgl.GL_BLEND)
        # bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2f(0, 0)
        bgl.glVertex2f(x1, y1)
        bgl.glTexCoord2f(0, 1)
        bgl.glVertex2f(x1, y2)
        bgl.glTexCoord2f(1, 1)
        bgl.glVertex2f(x2, y2)
        bgl.glTexCoord2f(1, 0)
        bgl.glVertex2f(x2, y1)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_TEXTURE_2D)
Exemple #21
0
    def __init__(self, region, space):
        import gpu
        import ctypes

        self.freed = False
        self.snap_objects = []
        self.drawn_count = 0
        self._offset_cur = 1 # Starts with index 1
        self.region = region
        self.rv3d = space.region_3d

        if self.rv3d.is_perspective:
            self.depth_range = Vector((space.clip_start, space.clip_end))
        else:
            self.depth_range = Vector((-space.clip_end, space.clip_end))

        self.proj_mat = None
        self.mval = Vector((0, 0))
        self._snap_mode = VERT | EDGE | FACE

        self.set_pixel_dist(12)

        self._offscreen = gpu.offscreen.new(self.region.width, self.region.height)

        self._texture = self._offscreen.color_texture
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._texture)

        NULL = bgl.Buffer(bgl.GL_INT, 1, (ctypes.c_int32 * 1).from_address(0))
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_R32UI, self.region.width, self.region.height, 0, bgl.GL_RED_INTEGER, bgl.GL_UNSIGNED_INT, NULL)
        del NULL

        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.glBindTexture(bgl.GL_TEXTURE_2D, 0)

        self.winsize = Vector((self._offscreen.width, self._offscreen.height))
Exemple #22
0
def get_texture(name):
    """nameが'icons'なら全体のテクスチャを返す
    :type name: str
    """
    if name in textures:
        return textures[name]

    if name in internal_icons:
        textures[name] = internal_icons[name]
        return textures[name]

    if name == 'icons':
        icon_type = 'icons'
    elif name in icons and icons[name] < 780:  # 780は'BRUSH_ADD':
        icon_type = 'icon'
    elif name in brush_icons:
        icon_type = 'brush'
    elif name in matcap_icons:
        icon_type = 'matcap'
    elif '.' in name:
        icon_type = 'image'
    else:
        return None

    dirname = os.path.dirname(os.path.abspath(__file__))

    if name == 'icons':
        filepath = os.path.join(dirname, ICON_FILE_NAME)
        img = load_image(filepath)
        if not img:
            return None
        sx, sy = img.size
        buf = bgl.Buffer(bgl.GL_FLOAT, 4 * sx * sy)
        img.gl_load(filter=bgl.GL_LINEAR, mag=bgl.GL_LINEAR)
        # TODO: 仕様変更があったので動作確認 -> img.bindcode
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, img.bindcode[0])
        bgl.glGetTexImage(bgl.GL_TEXTURE_2D, 0,
                          bgl.GL_RGBA, bgl.GL_FLOAT, buf)
        img.gl_free()
        img.user_clear()
        bpy.data.images.remove(img)
        x = y = 0
        w = sx
        h = sy

    elif icon_type == 'icon':
        if 'icons' not in textures:
            get_texture('icons')
        tex, buf, sx, sy, _x, _y, _w, _h = textures['icons']
        row, col = divmod(icons[name], 26)
        x = 10 + (40 + 2) * col
        y = 10 + (40 + 2) * row
        w = h = 32

    elif icon_type in ('brush', 'matcap'):
        if icon_type == 'brush':
            filepath = os.path.join(dirname, 'brushicons', brush_icons[name])
        else:
            filepath = os.path.join(dirname, 'matcaps', matcap_icons[name])
        buf, sx, sy = get_image_buffer(filepath)
        if not buf:
            return None
        x = y = 0
        w, h = sx, sy
    else:
        buf, sx, sy = get_image_buffer(name)
        if not buf:
            return None
        x = y = 0
        w, h = sx, sy

    if icon_type == 'icon':
        textures[name] = [tex, buf, sx, sy, x, y, w, h]
    else:
        texture = bgl.Buffer(bgl.GL_INT, 1)  # GLuint
        bgl.glGenTextures(1, texture)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture[0])
        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.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_S, bgl.GL_CLAMP)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_WRAP_T, bgl.GL_CLAMP)
        bgl.glTexImage2D(bgl.GL_TEXTURE_2D, 0, bgl.GL_RGBA,
                         sx, sy, 0, bgl.GL_RGBA, bgl.GL_FLOAT, buf)
        textures[name] = [texture[0], buf, sx, sy, x, y, w, h]
    return textures[name]
Exemple #23
0
 def interpolation(self, i):
     if i != self._interpolation:
         self.bind()
         bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, i)
         bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, i)
         self._interpolation = i
Exemple #24
0
    def draw(self, parent, context):
        #get the addon settings/prefs
        settings = context.user_preferences.addons['piemenus'].preferences

        #grab the biggest text dimensions that we already calced previously        
        biggestdimensionX = self.biggest_dim_x
        biggestdimensionY = self.biggest_dim_y
        
        for it in self.sliders:
            #draw some text above it.
            blf.size(0, self.text_size, self.text_dpi)
            dimension = blf.dimensions(0, it.id)

            x = it.x - dimension[0]*.5
            y = it.y + (it.height + dimension[1])* 0.5 + 2
            # Draw text
            blf.enable(0, blf.SHADOW)
            blf.shadow_offset(0, 0, 0)
            blf.shadow(0, 5, 0.0, 0.0, 0.0, 1.0)
            bgl.glColor3f(self.rt, self.gt, self.bt)
            
            blf.position(0, x, y, 0)
            blf.draw(0, it.id)
            blf.disable(0, blf.SHADOW)
            
            

            #draw left side one color
            bgl.glColor4f(self.rsSelected,self.gsSelected, self.bsSelected,1.0)
            pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, it.screen_left)
            
            #draw the right side another color
            bgl.glColor4f(self.rsInner,self.gsInner, self.bsInner,1.0)
            pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, it.screen_right)
            
            #Draw box outline
            bgl.glColor4f(self.rsOutline,self.gsOutline, self.bsOutline,1.0)           
            pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, it.screen_left)
            pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, it.screen_right)
            
            #put the text on top
            blf.enable(0, blf.KERNING_DEFAULT)
            prop_text = str(getattr(it.data, it.prop, 0))[0:4]
            #prop_text = "Test"
            dimensions2 = blf.dimensions(0,prop_text)
            x2 =it.x - dimensions2[0] * 0.5
            y2 = it.y - dimensions2[1] * 0.5
            blf.position(0, x2, y2, 0)
            bgl.glColor4f(self.rt, self.gt, self.bt, 1.0)
            blf.draw(0, prop_text)
            blf.disable(0, blf.KERNING_DEFAULT)
                
        for it in self.menu_items:
            sel = it == parent.current
            it_poll = it.poll(context)
 
            # center item on the circle
            #x = (self.menu_x + it.x) - (dimension[0] * 0.5)
            #y = (self.menu_y + it.y) - (dimension[1] * 0.5)

            blf.size(0, self.text_size, self.text_dpi)
            dimension = blf.dimensions(0, it.id)

            #needed for box centering
            x = (it.x) - (biggestdimensionX * 0.5)
            y = (it.y) - (biggestdimensionY * 0.5)

            #needed offset for text centering
            blf.size(0, self.text_size, self.text_dpi)
            dimension = blf.dimensions(0, it.id)
            xt = ((biggestdimensionX-dimension[0]) * 0.5)
            yt = ((biggestdimensionY-dimension[1]) * 0.5)

            # Draw background buttons
            if sel and it_poll:
                bgl.glColor4f(self.ris, self.gis, self.bis, self.ais)
            else:
                bgl.glColor4f(self.ri, self.gi, self.bi, self.ai)
 
            #self.gl_pie_slice(bgl.GL_POLYGON, 8, it, x,y,30,90) #***
            #http://www.opengl.org/archives/resources/faq/technical/rasterization.htm#rast0120
            #self._round_box(bgl.GL_POLYGON, x - 20, y - 5, x + biggestdimensionX + 20, y + biggestdimensionY + 5)          
            
            if it.screen_poly_bound:
                shape = it.screen_poly_bound            
                pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, shape)
                bgl.glColor4f(self.ro, self.go, self.bo, 1.0)
                pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, shape)
            
            bgl.glColor4f(self.ri, self.gi, self.bi, self.ai)
            #draw the circle
            if settings.clockBool:
                self._circle_(bgl.GL_TRIANGLE_FAN, (self.menu_x), (self.menu_y), 20)
            
                #draw the circle outline
                bgl.glColor4f(self.ro, self.go, self.bo, 1.0)
                self._circle_(bgl.GL_LINE_LOOP, (self.menu_x), (self.menu_y), 20)

                self._pointer_(bgl.GL_TRIANGLE_STRIP, (self.menu_x), (self.menu_y), self.pointerangle )
 
            # Draw text
            blf.enable(0, blf.SHADOW)
            blf.shadow_offset(0, 0, 0)
            blf.shadow(0, 5, 0.0, 0.0, 0.0, 1.0)
            if it_poll:
                bgl.glColor3f(self.rt, self.gt, self.bt)
            else:  # grayed out
                bgl.glColor3f(0.5, 0.5, 0.5)
            blf.position(0, x+xt, y+yt, 0)
            blf.draw(0, it.id)
            blf.disable(0, blf.SHADOW)
        
        
        #bind the named texure to GL_TEXTURE_2D
        #http://stackoverflow.com/questions/11217121/how-to-manage-memory-with-texture-in-opengl
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, settings.pieIconBindcode)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
        
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glEnable(bgl.GL_BLEND) 
        
        for it in self.menu_items:
            bgl.glColor4f(1, 1, 1, 1)
            if it.icon:
                #place the icon quad
                verts = it.screen_icon_quad
            
                bgl.glBegin(bgl.GL_QUADS)
            
                bgl.glTexCoord2f(it.tex_coords[0][0],it.tex_coords[0][1])
                bgl.glVertex2f(verts[0][0],verts[0][1])
                bgl.glTexCoord2f(it.tex_coords[1][0],it.tex_coords[1][1])
                bgl.glVertex2f(verts[1][0],verts[1][1])
                bgl.glTexCoord2f(it.tex_coords[2][0],it.tex_coords[2][1])
                bgl.glVertex2f(verts[2][0],verts[2][1])
                bgl.glTexCoord2f(it.tex_coords[3][0],it.tex_coords[3][1])
                bgl.glVertex2f(verts[3][0],verts[3][1])
            
                bgl.glEnd()
            
            #TODO
            #text value in center?
            #labe over top?    
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_TEXTURE_2D)