本文整理汇总了Python中shader.Shader.set_vertex_attrib方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.set_vertex_attrib方法的具体用法?Python Shader.set_vertex_attrib怎么用?Python Shader.set_vertex_attrib使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shader.Shader
的用法示例。
在下文中一共展示了Shader.set_vertex_attrib方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GrayScott
# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import set_vertex_attrib [as 别名]
#.........这里部分代码省略.........
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
# now we render to the actual window, hence the size is window's size.
self.set_viewport(self.width, self.height)
with self.render_shader:
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
def use_pattern(self, pattern):
self.pattern = pattern
rU, rV, feed, kill = SPECIES[pattern]
with self.reaction_shader:
self.reaction_shader.set_uniformf('feed', feed)
self.reaction_shader.set_uniformf('kill', kill)
self.reaction_shader.set_uniformf('rU', rU)
self.reaction_shader.set_uniformf('rV', rV)
def use_palette(self, palette):
self.palette = palette
color1, color2, color3, color4, color5 = palette
with self.render_shader:
self.render_shader.set_uniformf('color1', *color1)
self.render_shader.set_uniformf('color2', *color2)
self.render_shader.set_uniformf('color3', *color3)
self.render_shader.set_uniformf('color4', *color4)
self.render_shader.set_uniformf('color5', *color5)
def init_reaction_shader(self):
with self.reaction_shader:
self.reaction_shader.set_uniformi('uv_texture', 0)
self.reaction_shader.set_uniformf('dx', 1.0/self.tex_width)
self.reaction_shader.set_uniformf('dy', 1.0/self.tex_height)
# the order of the vertices and texcoords matters,
# since we will call 'GL_TRIANGLE_STRIP' to draw them.
self.reaction_shader.set_vertex_attrib('position', [(-1, -1), (1, -1), (-1, 1,), (1, 1)])
self.reaction_shader.set_vertex_attrib('texcoord', [(0, 0), (1, 0), (0, 1), (1, 1)])
self.reaction_shader.set_uniformf('u_mouse', -1, -1)
self.use_pattern(self.pattern)
def init_render_shader(self):
with self.render_shader:
self.render_shader.set_uniformi('uv_texture', 0)
self.render_shader.set_vertex_attrib('position', [(-1, -1), (1, -1), (-1, 1), (1, 1)])
self.render_shader.set_vertex_attrib('texcoord', [(0, 0), (1, 0), (0, 1), (1, 1)])
self.use_palette(self.palette)
def update_mouse(self, *u_mouse):
self.set_viewport(self.tex_width, self.tex_height)
with self.fbo:
with self.reaction_shader:
self.reaction_shader.set_uniformf('u_mouse', *u_mouse)
def on_mouse_press(self, x, y, button, modifiers):
self.mouse_down = True
bx = x / float(self.width)
by = y / float(self.height)
self.update_mouse(bx, by)
def on_mouse_release(self, x, y, button, modifiers):
self.mouse_down = False
self.update_mouse(-1, -1)
def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
if self.mouse_down:
bx = x / float(self.width)
by = y / float(self.height)
self.update_mouse(bx, by)