本文整理汇总了Python中kivy.graphics.Fbo类的典型用法代码示例。如果您正苦于以下问题:Python Fbo类的具体用法?Python Fbo怎么用?Python Fbo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fbo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_screen_fbo
def make_screen_fbo(self, screen):
fbo = Fbo(size=screen.size)
with fbo:
ClearColor(0, 1, 0, 1)
ClearBuffers()
fbo.add(screen.canvas)
return fbo
示例2: load_walls
def load_walls(state, base_name, background_file, tile_file, with_collisions=True):
"""
TODO
"""
tile_size = screen.get_tile_size(state)
int_tile_size = int(tile_size)
background_texture = Image(source=background_file).texture
walls_texture = Image(source=tile_file).texture
for tile_name, origin_xy, collision in tiles_origin_table:
full_tile_name = base_name + tile_name
wall_texture = walls_texture.get_region(
origin_xy[0] * int_tile_size,
origin_xy[1] * int_tile_size,
int_tile_size,
int_tile_size)
tile_texture = Texture.create(size=(int_tile_size, int_tile_size), colorfmt='rgba')
fbo = Fbo(size=(int_tile_size, int_tile_size), texture=tile_texture)
with fbo:
Color(1, 1, 1)
Rectangle(pos=(0, 0), size=tile_texture.size, texture=background_texture)
Rectangle(pos=(0, 0), size=tile_texture.size, texture=wall_texture)
fbo.draw()
if not with_collisions:
collision = None
tiles.add_tile_def(state, full_tile_name, tile_texture, collision)
示例3: FboTest
class FboTest(Widget):
def __init__(self, **kwargs):
super(FboTest, self).__init__(**kwargs)
self.positions = [
(260.0, 260.0),
(192.0, 192.0),
(96.0, 192.0),
(192.0, 96.0),
(96.0, 96.0),
(32.0, 192.0),
(192.0, 32.0),
(32.0, 32.0)
]
self.fbo = Fbo(size=(256, 256))
with self.fbo:
Color(0.56789, 0, 0, 1)
Rectangle(size=(256, 64))
Color(0, 0.56789, 0, 1)
Rectangle(size=(64, 256))
Color(0.56789, 0, 0, .5)
Rectangle(pos=(64, 64), size=(192, 64))
Color(0, 0.56789, 0, .5)
Rectangle(pos=(64, 64), size=(64, 192))
self.fbo.draw()
示例4: __init__
def __init__(self, code, **kwargs):
Fbo.__init__(self, **kwargs)
self.canvas = RenderContext()
shader = self.canvas.shader
shader.fs = header + code
if not shader.success:
print '! Shader compilation failed (GLSL)'
assert False
示例5: circle_fs
def circle_fs(size=(64, 64)):
fbo = Fbo(size=size)
fbo.shader.fs = circle_test
with fbo:
Color(1, 1, 1)
Rectangle(size=size)
fbo.draw()
return fbo.texture
示例6: Scaled
class Scaled(Widget):
def __init__(self, **kwargs):
super(Scaled, self).__init__(**kwargs)
self.elements = []
self.pointsize = 5 # this multiplies by two according to kivy docs
with self.canvas:
self._fbo = Fbo(size=self.size)
self._rect = Rectangle(texture=self._fbo.texture)
with self._fbo:
Color(1, 1, 1)
self._fborect = Rectangle(size=self._fbo.size)
Color(0, 0, 1)
self._points = Point(pointsize=self.pointsize)
self._fbo.add_reload_observer(self._clear_fbo)
self.bind(pos=self._update_rect, size=self._update_rect)
def drawpoint(self, x, y):
self.elements.append([x, y])
self._points.add_point(x, y)
def draw(self, matrix):
self._points.points = []
self._clear_fbo()
for point in matrix:
x = int(point[0] * (self.pointsize * 2) + self.pointsize)
y = int(point[1] * (self.pointsize * 2) + self.pointsize)
self.drawpoint(x, y)
# RELOADING THE BUFFER AT ANY CHANGE
def _clear_fbo(self, fbo=None):
""" This will reload the framebufferer either by the call of the
observer or by the deletion of a point"""
if fbo is None:
fbo = self._fbo
fbo.bind()
fbo.clear_buffer()
fbo.add(Color(1, 1, 1))
fbo.add(self._fborect)
fbo.add(Color(0, 0, 1))
fbo.add(self._points)
fbo.release()
def _update_rect(self, instance, value):
self._fbo.size = instance.size
self._fborect.size = instance.size
self._rect.size = instance.size
self._rect.pos = instance.pos
self._rect.texture = self._fbo.texture
示例7: test_fbo_pixels
def test_fbo_pixels(self):
from kivy.graphics import Fbo, ClearColor, ClearBuffers, Ellipse
fbo = Fbo(size=(512, 512))
with fbo:
ClearColor(0, 0, 0, 1)
ClearBuffers()
Ellipse(pos=(100, 100), size=(100, 100))
fbo.draw()
data = fbo.pixels
fbo.texture.save('results.png')
示例8: make_screen_fbo
def make_screen_fbo(self, screen):
fbo = Fbo(size=screen.size)
with fbo:
ClearColor(*self.clearcolor)
ClearBuffers()
fbo.add(screen.canvas)
with fbo.before:
PushMatrix()
Translate(-screen.x, -screen.y, 0)
with fbo.after:
PopMatrix()
return fbo
示例9: FboCapture
class FboCapture(FloatLayout):
texture = ObjectProperty(None)
texture_thumb = ObjectProperty(None)
thumb_size = ListProperty([50, 50])
def __init__(self, **kwargs):
self.canvas = Canvas()
with self.canvas:
self.fbo = Fbo(size=self.size)
self.fbo_thumb = Fbo(size=self.thumb_size)
with self.fbo:
Color(0, 0, 0)
self.fbo_rect = Rectangle(size=self.size)
self.texture = self.fbo.texture
with self.fbo_thumb:
Color(1, 1, 1)
self.fbo_thumb_rect = Rectangle(size=self.thumb_size)
super(FboCapture, self).__init__(**kwargs)
def on_size(self, instance, value):
w, h = value
ratio = float(w) / h
if w > h:
w = 160
h = w / ratio
else:
h = 160
w = h * ratio
w = max(1, w)
h = max(1, h)
self.thumb_size = int(w), int(h)
self.fbo.size = value
self.fbo_rect.size = value
self.texture = self.fbo.texture
self.fbo_thumb_rect.texture = self.fbo.texture
def on_thumb_size(self, instance, value):
self.fbo_thumb.size = value
self.fbo_thumb_rect.size = value
self.texture_thumb = self.fbo_thumb.texture
def add_widget(self, child):
child.parent = self
self.children.insert(0, child)
self.fbo.add(child.canvas)
def remove_widget(self, child):
self.children.remove(child)
self.fbo.remove(child.canvas)
示例10: hue_transform
def hue_transform(source, hue, size=(64, 64)):
fbo = Fbo(size=size)
fbo.shader.fs = hue_xfo
# use the shader on the entire surface
fbo['hueAdjust'] = float(hue)
with fbo:
Color(1, 1, 1)
Rectangle(size=size, source=source)
fbo.draw()
return fbo.texture
示例11: advanced_gradient
def advanced_gradient(border_color=(1, 1, 0), center_color=(1, 0, 0), size=(64, 64),fs=radial_grd_fs):
fbo = Fbo(size=size)
fbo.shader.fs = fs
# use the shader on the entire surface
fbo['border_color'] = map(float, border_color)
fbo['center_color'] = map(float, center_color)
with fbo:
Color(1, 1, 1)
Rectangle(size=size)
fbo.draw()
return fbo.texture
示例12: test_fbo_pixels
def test_fbo_pixels(self):
from kivy.graphics import Fbo, ClearColor, ClearBuffers, Ellipse
fbo = Fbo(size=(512, 512))
with fbo:
ClearColor(0, 0, 0, 1)
ClearBuffers()
Ellipse(pos=(100, 100), size=(100, 100))
fbo.draw()
data = fbo.pixels
import pygame
surface = pygame.image.fromstring(data, (512, 512), 'RGBA', True)
pygame.image.save(surface, "results.png")
示例13: insert_color_ellipse
def insert_color_ellipse(state, texture_w, texture_h, texture_name, c_r, c_g, c_b):
"""
TODO
"""
tile_size = screen.get_tile_size(state)
texture_w *= tile_size
texture_h *= tile_size
texture = Texture.create(size=(texture_w, texture_h), colorfmt='rgba')
fbo = Fbo(size=(texture_w, texture_h), texture=texture)
with fbo:
Color(c_r, c_g, c_b)
Ellipse(pos=(0, 0), size=(texture_w, texture_h))
fbo.draw()
insert(state, texture_name, texture)
示例14: __init__
def __init__(self, **kwargs):
# Make sure opengl context exists
EventLoop.ensure_window()
self.canvas = RenderContext(use_parent_projection=True,
use_parent_modelview=True)
with self.canvas:
self.fbo = Fbo(size=self.size)
with self.fbo.before:
PushMatrix()
with self.fbo:
ClearColor(0, 0, 0, 0)
ClearBuffers()
self._background_color = Color(*self.background_color)
self.fbo_rectangle = Rectangle(size=self.size)
with self.fbo.after:
PopMatrix()
super(EffectWidget, self).__init__(**kwargs)
Clock.schedule_interval(self._update_glsl, 0)
fbind = self.fbind
fbo_setup = self.refresh_fbo_setup
fbind('size', fbo_setup)
fbind('effects', fbo_setup)
fbind('background_color', self._refresh_background_color)
self.refresh_fbo_setup()
self._refresh_background_color() # In case thi was changed in kwargs
示例15: _prepare_fbo
def _prepare_fbo(self, *args):
# put all the current canvas into an FBO
# then use the fbo texture into a Quad, for animating when disable
# create the Fbo
self.fbo = Fbo(size=(1, 1))
with self.fbo.before:
self.g_translate = Translate(self.x, self.y)
self.orig_canvas = self.canvas
self.fbo.add(self.canvas)
# create a new Canvas
self.canvas = Canvas()
self.canvas.add(self.fbo)
with self.canvas:
Color(1, 1, 1)
self.g_quad = Quad(texture=self.fbo.texture)
# replace the canvas from the parent with the new one
self.parent.canvas.remove(self.orig_canvas)
self.parent.canvas.add(self.canvas)
# ensure we'll be updated when we'll change position
self.bind(pos=self._update_mesh, size=self._update_mesh, alpha_rotation=self._update_mesh)
self._update_mesh()