本文整理汇总了Python中kivy.graphics.Fbo.clear_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python Fbo.clear_buffer方法的具体用法?Python Fbo.clear_buffer怎么用?Python Fbo.clear_buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.Fbo
的用法示例。
在下文中一共展示了Fbo.clear_buffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VTKWidget
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import clear_buffer [as 别名]
class VTKWidget(Widget):
def __init__(self, **kwargs):
super(VTKWidget,self).__init__(**kwargs)
self.setupVTK()
def updateVTK(self, *largs):
self.fbo.ask_update()
self.canvas.ask_update()
def setupVTK(self):
Clock.schedule_interval(self.updateVTK, 1 / 1.)
with self.canvas:
self.fbo = Fbo(size=(512,512), clear_color=(.3, .3, .3, .8), push_viewport=True, with_depthbuffer=True)
self.size = self.fbo.size
Color(0, 0, 1)
Rectangle(pos=self.pos, size=self.size, texture=self.fbo.texture)
Callback(self.drawVTK, reset_context=True)
def drawVTK(self, instr):
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
VTKClock.tick()
glViewport(0,0,512,512)
self.fbo.clear_buffer()
#push GL state of Kivy
glUseProgram(0)
glPushAttrib(GL_ALL_ATTRIB_BITS)
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
renWin.Render()
#pop previous state of Kivy
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glPopAttrib()
示例2: PandaView
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import clear_buffer [as 别名]
class PandaView(Widget):
cam_pos = ListProperty([0, 0, 0])
cam_lookat = ListProperty([0, 0, 0])
def __init__(self, **kwargs):
super(PandaView, self).__init__(**kwargs)
self.setup_panda()
def load_model(self, filename):
return self.msb.load_model(filename)
def update_panda(self, *largs):
self.fbo.ask_update()
self.canvas.ask_update()
def setup_panda(self, *largs):
self.msb = ModelShowbase()
self.msb.camLens.setFov(52.0)
self.msb.camLens.setNearFar(1.0, 10000.0)
with self.canvas:
self.fbo = Fbo(size=self.size, clear_color=(0.3, 0.3, 0.3, 0.2))
Color(1, 1, 1)
self.viewport = Rectangle(pos=self.pos, size=self.size, texture=self.fbo.texture)
Callback(self.draw_panda, reset_context=True)
Clock.schedule_interval(self.update_panda, 1 / 60.0)
def draw_panda(self, instr):
self.fbo.clear_buffer()
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
self.msb.taskMgr.step()
self.msb.camera.setPos(Point3(*self.cam_pos))
self.msb.camera.lookAt(Point3(*self.cam_lookat), Vec3(0, 0, 1))
def toggle_show_collision_boxes(self):
""" Debug visualization: Toggle drawing of collision nodes.
Off by default.
"""
# See http://www.panda3d.org/apiref.php?page=NodePath
matches = self.msb.render.findAllMatches("**/+CollisionNode")
if self._show_collision_boxes:
matches.hide()
else:
matches.show()
self._show_collision_boxes = not self._show_collision_boxes
return self._show_collision_boxes
def set_show_collision_boxes(self, value):
if self._show_collision_boxes and value:
return
if not self._show_collision_boxes and not value:
return
self.toggle_show_collision_boxes()
def to_panda_window(self, x, y):
"""
Convert Kivy window coordinates to panda window coordinates.
The panda window coordinate system's origin is in the middle of the window,
with the x-axis going positively to the right and the y axis pointing
positively up, where coordinates in all directions are normalized to a
float of maximum value 1. (i.e., top right corner is (1., 1.)).
"""
w, h = self.size
w2 = w / 2.0
h2 = h / 2.0
x = (x - w2) / w2
y = (y - h2) / h2
return x, y
def on_size(self, *args):
self.fbo.size = self.size
self.viewport.size = self.size
props = WindowProperties()
props.setSize(LVector2i(*self.size))
self.msb.win.requestProperties(props)
示例3: EffectWidget
# 需要导入模块: from kivy.graphics import Fbo [as 别名]
# 或者: from kivy.graphics.Fbo import clear_buffer [as 别名]
class EffectWidget(FloatLayout):
fs = StringProperty(None)
# Texture of the final Fbo
texture = ObjectProperty(None)
# Rectangle clearing Fbo
fbo_rectangle = ObjectProperty(None)
# List of effect strings
effects = ListProperty([])
# One extra Fbo for each effect
fbo_list = ListProperty([])
effect_mask = None
motion_effect = None
def __init__(self, **kwargs):
# Make sure opengl context exists
EventLoop.ensure_window()
self.mask_effect = kwargs.get("mask_effect", None)
self.motion_effect = kwargs.get("motion_effect", None)
self.canvas = RenderContext(use_parent_projection=True,
use_parent_modelview=True)
self.size = C_SIZE
with self.canvas:
#self._viewport = Rectangle(size=(800,600), pos=self.pos)
self.fbo = Fbo(size=C_SIZE, with_depthbuffer=True, compute_normal_mat=True,
clear_color=(0.3, 0.3, 0.7, 1))
with self.fbo.before:
#Rectangle(size=(800, 600))
PushMatrix()
self.fbo_translation = Translate(-self.x, -self.y, 0)
BindTexture(texture=self.mask_effect.texture, index=4)
BindTexture(texture=self.motion_effect.texture, index=5)
with self.fbo:
Color(0, 0, 0)
BindTexture(texture=self.mask_effect.texture, index=4)
BindTexture(texture=self.motion_effect.texture, index=5)
self.fbo_rectangle = Rectangle(size=C_SIZE)
self._instructions = InstructionGroup()
with self.fbo.after:
PopMatrix()
self.cbs = Callback(self.reset_gl_context)
super(EffectWidget, self).__init__(**kwargs)
self.size = C_SIZE
Clock.schedule_interval(self.update_glsl, 0)
self._instructions.add(Callback(self.setup_gl_context))
self.refresh_fbo_setup()
Clock.schedule_interval(self.update_fbos, 0)
def on_pos(self, *args):
self.fbo_translation.x = -self.x
self.fbo_translation.y = -self.y
def on_size(self, instance, value):
self.fbo.size = C_SIZE
self.fbo_rectangle.size = C_SIZE
self.refresh_fbo_setup()
#self._viewport.texture = self.fbo.texture
#self._viewport.size = value
def setup_gl_context(self, *args):
glEnable(GL_DEPTH_TEST)
self.fbo.clear_buffer()
#for fbo in self.fbo_list:
# fbo.clear_buffer()
def reset_gl_context(self, *args):
glDisable(GL_DEPTH_TEST)
def update_glsl(self, *largs):
time = Clock.get_boottime()
resolution = [float(size) for size in C_SIZE]
self.canvas['time'] = time
self.canvas['resolution'] = resolution
self.canvas['texture4'] = 4
self.canvas['texture5'] = 5
for fbo in self.fbo_list:
fbo['time'] = time
fbo['resolution'] = resolution
fbo['texture4'] = 4
fbo['texture5'] = 5
#.........这里部分代码省略.........