コード例 #1
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)
コード例 #2
0
ファイル: window.py プロジェクト: Hubber116sx/BGECore
	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)
コード例 #3
0
def draw_callback_common(self, context, ots):
    if Pref.use_alpha_clip:
        bgl.glAlphaFunc(bgl.GL_GREATER, 0.1)
        bgl.glEnable(bgl.GL_ALPHA_TEST)

    orig_is_enabled_depthtest = bgl.glIsEnabled(bgl.GL_DEPTH_TEST)
    bgl.glEnable(bgl.GL_DEPTH_TEST)

    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_TEXTURE_2D)

    texcos = [(0.,0.), (1.,0.), (1.,1.), (0.,1.)]


    fr = context.scene.frame_current
    for l,obj,tex in ots:
        ps = [obj.matrix_world*v.co for v in obj.data.vertices[0:4]]
        if tex.blendmode == BlendMode.ALPHAOVER:
            bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
            bgl.glBlendEquation(bgl.GL_FUNC_ADD)
        elif tex.blendmode == BlendMode.ADDITIVE:
            bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE)
            bgl.glBlendEquation(bgl.GL_FUNC_ADD)
        tex.bind()
        bgl.glBegin(bgl.GL_QUADS)
        for p,t in zip(ps, texcos):
            bgl.glTexCoord2f(*t)
            bgl.glVertex3f(*p)
        bgl.glEnd()

    #bgl.glDepthMask(bgl.GL_TRUE)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    bgl.glBlendEquation(bgl.GL_FUNC_ADD)
    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glDisable(bgl.GL_BLEND)
    if Pref.use_alpha_clip:
        bgl.glDisable(bgl.GL_ALPHA_TEST)
    if not orig_is_enabled_depthtest:
        bgl.glDisable(bgl.GL_DEPTH_TEST)
コード例 #4
0
ファイル: label.py プロジェクト: Hubber116sx/BGECore
	def draw(self):
		if self.visible == False: return
		module.post_draw_step += 1
		
		cam = self.scene.active_camera
		orth = cam.ortho_scale
		
		height = render.getWindowHeight()
		width = render.getWindowWidth()
		near = cam.near
		far = cam.far
		h = cam.worldPosition.z
		font_id = Label._fontname_id[self._font]
		unit = width/orth
		self._glunit = unit
		rpos = self._position - cam.worldPosition
		
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, width, 0, height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
		
		bgl.glEnable(bgl.GL_BLEND)
		bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
		bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)
		
		#Z AXIS
		oh = (far-near)/2
		ortho_unit = 1/oh
		dh = oh

		pos = list([width/2+rpos[0]*unit, height/2+rpos[1]*unit, dh*ortho_unit + rpos[2]*ortho_unit])
		if self._lastscale != self.scale or True:
			blf.size(font_id, int(self.scale.x*unit), 72)
		else:
			if self._lastorth != orth:
				sc = (float(self._lastorth) / float(orth)) * self.scale.x
				bgl.glScalef(sc,sc,1)
				print(str(self._lastorth) + " " + str(orth))
				pos[0] /= sc
				pos[1] /= sc
				
			else:
				self._lastorth = orth
		
		x, y = blf.dimensions(font_id, self._text) #NOTE: Always after blf.size()
		
		if self.align == ALIGN_CENTER:
			pos[0] -= (x)/2 * math.cos(self._rotation.z)
			pos[1] -= x/2 * math.sin(self._rotation.z)
		if self.align == ALIGN_RIGHT:
			pos[0] -= x * math.cos(self._rotation.z)
			pos[1] -= x * math.sin(self._rotation.z)
			
		if self.middle_height == True:
			pos[0] -= y/4 * math.sin(self._rotation.z)
			pos[1] -= y/4 * math.cos(self._rotation.z)
		
		blf.position(font_id, pos[0], pos[1], pos[2])
		blf.enable(font_id, blf.ROTATION)
		if self.rotation.z > 0.01 or self.rotation.z < -0.01:
			blf.rotation(font_id, self._rotation.z)
		else:
			blf.rotation(font_id, 0)
		
		if self.shadow == True:
			blf.position(font_id, pos[0]+self.shadow_offset[0], pos[1]+self.shadow_offset[1], pos[2])
			bgl.glColor4f(*self.shadow_color)
			blf.blur(font_id, self.shadow_blur)
			blf.draw(font_id, self._text)
			blf.position(font_id, pos[0], pos[1], pos[2])
			
		bgl.glColor4f(*self._color)
		blf.blur(font_id, self.blur)
		blf.draw(font_id, self._text)
		
		blf.disable(font_id, blf.ROTATION)
		
		self._lastscale = self.scale
コード例 #5
0
    def draw(self):
        if self.visible == False: return
        module.post_draw_step += 1

        cam = self.scene.active_camera
        orth = cam.ortho_scale

        height = render.getWindowHeight()
        width = render.getWindowWidth()
        near = cam.near
        far = cam.far
        h = cam.worldPosition.z
        font_id = Label._fontname_id[self._font]
        unit = width / orth
        self._glunit = unit
        rpos = self._position - cam.worldPosition

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, width, 0, height)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
        bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)

        #Z AXIS
        oh = (far - near) / 2
        ortho_unit = 1 / oh
        dh = oh

        pos = list([
            width / 2 + rpos[0] * unit, height / 2 + rpos[1] * unit,
            dh * ortho_unit + rpos[2] * ortho_unit
        ])
        if self._lastscale != self.scale or True:
            blf.size(font_id, int(self.scale.x * unit), 72)
        else:
            if self._lastorth != orth:
                sc = (float(self._lastorth) / float(orth)) * self.scale.x
                bgl.glScalef(sc, sc, 1)
                print(str(self._lastorth) + " " + str(orth))
                pos[0] /= sc
                pos[1] /= sc

            else:
                self._lastorth = orth

        x, y = blf.dimensions(font_id,
                              self._text)  #NOTE: Always after blf.size()

        if self.align == ALIGN_CENTER:
            pos[0] -= (x) / 2 * math.cos(self._rotation.z)
            pos[1] -= x / 2 * math.sin(self._rotation.z)
        if self.align == ALIGN_RIGHT:
            pos[0] -= x * math.cos(self._rotation.z)
            pos[1] -= x * math.sin(self._rotation.z)

        if self.middle_height == True:
            pos[0] -= y / 4 * math.sin(self._rotation.z)
            pos[1] -= y / 4 * math.cos(self._rotation.z)

        blf.position(font_id, pos[0], pos[1], pos[2])
        blf.enable(font_id, blf.ROTATION)
        if self.rotation.z > 0.01 or self.rotation.z < -0.01:
            blf.rotation(font_id, self._rotation.z)
        else:
            blf.rotation(font_id, 0)

        if self.shadow == True:
            blf.position(font_id, pos[0] + self.shadow_offset[0],
                         pos[1] + self.shadow_offset[1], pos[2])
            bgl.glColor4f(*self.shadow_color)
            blf.blur(font_id, self.shadow_blur)
            blf.draw(font_id, self._text)
            blf.position(font_id, pos[0], pos[1], pos[2])

        bgl.glColor4f(*self._color)
        blf.blur(font_id, self.blur)
        blf.draw(font_id, self._text)

        blf.disable(font_id, blf.ROTATION)

        self._lastscale = self.scale