def render_dot(self, size): # Render an antialiased dot using the circle shader. with self.canvas: dot_fbo = Fbo(size=size) # Install the shader, and check it compiled. original_vs = dot_fbo.shader.vs original_fs = dot_fbo.shader.fs dot_fbo.shader.vs = circle_vertex_shader dot_fbo.shader.fs = circle_fragment_shader if not dot_fbo.shader.success: # Shader didn't compile, just render an ellipse. dot_fbo.shader.vs = original_vs dot_fbo.shader.fs = original_fs with dot_fbo: Ellipse(pos=(2, 2), size=(size[0]-4, size[1]-4)) else: # Render a rectangle with the circle shader. border = 3.0 dot_fbo['centre'] = (size[0] * 0.5, size[1] * 0.5) dot_fbo['radius'] = max(size[0] * 0.5 - border, 0.0) dot_fbo['border'] = border with dot_fbo: Callback(lambda *_args: glBlendFunc(GL_ONE, GL_ZERO)) Rectangle(size=size) Callback(lambda *_args: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)) return dot_fbo
def create_blend_instruction(entity): """Create and return an instruction for setting the blend mode (if required)""" if isinstance(entity, Myrmidon_Backend._Text) or isinstance(entity, Myrmidon_Backend._Polygon): # text images are generated with regular alpha - use standard blend mode return Callback(lambda instr: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)) else: # all other images are loaded with pre-multiplied alpha. Use appropriate blend mode return Callback(lambda instr: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA))
def reset_gl_context(self): gl.glEnable(gl.GL_BLEND) gl.glDisable(gl.GL_DEPTH_TEST) gl.glDisable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_STENCIL_TEST) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
def generate_text_image(self): glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) label = self.generate_label() label.text = self._text label.texture_update() if not label.texture: self.text_image_size = (0, 0) self.image = Myrmidon_Backend.Image() return self.text_image_size = label.texture_size tex = Texture.create(size=label.texture.size, mipmap=True) tex.blit_buffer(label.texture.pixels, colorfmt='rgba', bufferfmt='ubyte') tex.flip_vertical() self.image = Myrmidon_Backend.Image(tex)
def _set_blend_func(self, instruction): glBlendFunc(self.blend_factor_source, self.blend_factor_dest)
def reset_blend_func(instr): '''Normal alpha''' glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def _set_blend_func(self, instruction): '''Controller for the Gabor blending to the background color glBlendFunc(starting RGBA values, desired RGBA values)''' glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA)
def _set_blend_func(self, instruction): # glBlendFunc(self.blend_factor_source, self.blend_factor_dest) # glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE)
def _set_blend_func(self, instruction): #glBlendFunc(self.blend_factor_source, self.blend_factor_dest) #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE)
def _reset_blend_func(self, instruction): glBlendFunc(self.reset_blend_factor_source, self.reset_blend_factor_dest)
def glBlendFunc(): """Blend function for blending images onscreen.""" glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def draw(self, skeleton): self.shapes.clear() skeletonX = skeleton.getX() skeletonY = skeleton.getY() glEnable(GL_BLEND) srcFunc = GL_ONE if self.preMultipliedAlpha else GL_SRC_ALPHA glBlendFunc(srcFunc, GL_ONE_MINUS_SRC_ALPHA) bones = skeleton.getBones() if self.drawBones: self.shapes.add(self.boneLineColor) for i in range(len(bones)): bone = bones[i] if bone.parent is None: continue x = skeletonX + bone.data.length * bone.m00 + bone.worldX y = skeletonY + bone.data.length * bone.m10 + bone.worldY self.shapes.add( Line(points=[ skeletonX + bone.worldX, skeletonY + bone.worldY, x, y ], width=self.boneWidth * self.scale)) self.shapes.add(Line(circle=(skeletonX, skeletonY, 4 * self.scale))) if self.drawRegionAttachments: self.shapes.add(self.attachmentLineColor) slots = skeleton.getSlots() for i in range(len(slots)): slot = slots[i] attachment = slot.attachment if isinstance(attachment, RegionAttachment): attachment.updateWorldVertices(slot, False) vertices = attachment.getWorldVertices() self.shapes.add( Line(points=([ vertices[X1], vertices[Y1], vertices[X2], vertices[Y2] ]))) self.shapes.add( Line(points=([ vertices[X2], vertices[Y2], vertices[X3], vertices[Y3] ]))) self.shapes.add( Line(points=([ vertices[X3], vertices[Y3], vertices[X4], vertices[Y4] ]))) self.shapes.add( Line(points=([ vertices[X4], vertices[Y4], vertices[X1], vertices[Y1] ]))) if self.drawMeshHull or self.drawMeshTriangles: slots = skeleton.getSlots() for i in range(len(slots)): slot = slots[i] attachment = slot.attachment vertices = None triangles = None hullLength = 0 if isinstance(attachment, MeshAttachment): attachment.updateWorldVertices(slot, False) vertices = attachment.getWorldVertices() triangles = attachment.getTriangles() hullLength = attachment.getHullLength() elif isinstance(attachment, SkinnedMeshAttachment): attachment.updateWorldVertices(slot, False) vertices = attachment.getWorldVertices() triangles = attachment.getTriangles() hullLength = attachment.getHullLength() if vertices is None or triangles is None: continue if self.drawMeshTriangles: self.shapes.add(self.triangleLineColor) for ii in range(0, len(triangles), 3): v1, v2, v3 = triangles[ii] * 5, triangles[ ii + 1] * 5, triangles[ii + 3] * 5 self.shapes.add( Line(points=[ vertices[v1], vertices[v1 + 1], vertices[v2], vertices[v2 + 1], vertices[v3], vertices[v3 + 1] ])) if self.drawMeshHull and hullLength > 0: self.shapes.add(self.attachmentLineColor) hullLength = hullLength / 2 * 5 lastX, lastY = vertices[hullLength - 5], vertices[hullLength - 4] for ii in range(0, hullLength, 5): x, y = vertices[ii], vertices[ii + 1] self.shapes.add(Line(points=[x, y, lastX, lastY])) lastX = x lastY = y if self.drawBoundingBoxes: bounds = self.bounds bounds.update(skeleton, True) self.shapes.add(self.aabbColor) self.shapes.add( Rectangle(x=bounds.getMinX(), y=bounds.getMinY(), width=bounds.getWidth(), height=bounds.getHeight())) self.shapes.add(self.boundingBoxColor) polygons = bounds.getPolygons() for polygon in polygons: self.shapes.add(Line(points=polygon)) if self.drawBones: self.shapes.add(self.boneOriginColor) for bone in bones: self.shapes.add(Color(0, 1, 0, 1)) self.shapes.add( Line(circle=(skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * self.scale))) del bones
def create_blend_instruction(entity): """Create and return an instruction for setting the blend mode (if required)""" return Callback(lambda instr: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA))
def _set_blend_mode(self, instruction = None): gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO); gl.glBlendFuncSeparate(gl.GL_ONE, gl.GL_ZERO, gl.GL_ONE, gl.GL_ZERO);
def _unset_blend_mode(self, instruction = None): gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA); gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA, gl.GL_ONE, gl.GL_ONE);
def new_color(self, *args): with self.fbo: Rectangle(size = self.size, texture = self.tex2.texture) self.color = Color(*self.mood) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) Rectangle(size = self.size, texture = self.tex.texture)
def _reset_blend_func(self, instruction): '''Reset of the Gabor blending properties for creation of new stimuli glBlendFunc(starting RGBA values, desired RGBA values)''' glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def _reset_blend_func(self, instruction): glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def select_blend_func(instr): '''Premultiplied alpha''' glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
def new_color(texture, color, x, y, fbo): with fbo: tex_region = texture.get_region(x, y, 4, 4) fbo.add(color) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) Rectangle(size=(4, 4), pos=(x, y), texture=tex_region)