本文整理汇总了Python中shader.Shader.from_files方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.from_files方法的具体用法?Python Shader.from_files怎么用?Python Shader.from_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shader.Shader
的用法示例。
在下文中一共展示了Shader.from_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import from_files [as 别名]
def __init__(self, width, height, pattern, scale=2):
'''
width, height:
size of the window in pixels.
scale:
the size of the texture is (width//scale) x (height//scale).
pattern:
a name in dict 'species'.
'''
pyglet.window.Window.__init__(self, width, height, caption='GrayScott Simulation',
visible=False, vsync=False)
# we will need two shaders, one for computing the reaction and diffusion,
# and one for coloring the uv_texture.
self.reaction_shader = Shader.from_files('default.vert', 'reaction.frag')
self.render_shader = Shader.from_files('default.vert', 'render.frag')
self.pattern = pattern
self.palette = GrayScott.palette_default
self.tex_width = width // scale
self.tex_height = height // scale
self.uv_texture = create_uv_texture(width // scale, height // scale)
# the texture is bind to unit '0'.
gl.glActiveTexture(gl.GL_TEXTURE0)
gl.glBindTexture(self.uv_texture.target, self.uv_texture.id)
# set the uniforms and attributes in the two shaders.
self.init_reaction_shader()
self.init_render_shader()
# we need a framebuffer to do the offscreen rendering.
# once we finished computing the reaction-diffusion step with the reaction_shader,
# we render the result to this 'invisible' buffer since we do not want to show it.
# the final image is further colored and will be rendered to the window.
with FrameBuffer() as self.fbo:
self.fbo.attach_texture(self.uv_texture)
# why do we need this?
# the reason is in the 'on_mouse_drag' function.
self.mouse_down = False