当前位置: 首页>>代码示例>>Python>>正文


Python Shader.uniformfv方法代码示例

本文整理汇总了Python中shader.Shader.uniformfv方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.uniformfv方法的具体用法?Python Shader.uniformfv怎么用?Python Shader.uniformfv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shader.Shader的用法示例。


在下文中一共展示了Shader.uniformfv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformfv [as 别名]
class Unwrapper:
    """
    This unwrapper takes an image path and a parsed frame and fulfills
    the operations required to draw the unwrapped image.

    The draw operations MUST be called inside of the "on_draw" callback
    passed to "start_unwrap_window" in order to be fulfilled.  This class
    cannot function without an OpenGL window.
    """
    def __init__(self):

        # Create the shader.
        self.shader = Shader(vertex_shader, fragment_shader)

        # Set the texture unit.
        self.shader.bind()
        self.shader.uniformi('tex0', 0)
        self.shader.unbind()

        # Create a quad geometry to fit the whole window that will be the target of our drawing.
        self.batch = pyglet.graphics.Batch()
        self.batch.add(4, GL_QUADS, None, ('v2i', (0,0, 1,0, 1,1, 0,1)), ('t2f', (0,0, 1,0, 1,1, 0,1)))

    def update(self, img_path, frame):
        """
        Update the texture to the given image path, and update the shaders with the new
        frame information to unwrap the given image correctly.
        """

        # Recalculate the variables required to unwrap the new image.
        projector = PolygonProjector(frame.center_point, frame.center_vertices)
        angle_bounds = [v.angle for v in projector.vertices]
        radii = [p.center_dist for p in projector.projectors]
        angles = [p.center_angle for p in projector.projectors]

        # Load the new image, and update the size variables.
        self.texture = pyglet.image.load(img_path).get_texture()
        region_w, region_h = self.texture.width, self.texture.height
        actual_w, actual_h = self.texture.owner.width, self.texture.owner.height

        # Update the shader variables.
        self.shader.bind()
        self.shader.uniformf('region_size', region_w, region_h)
        self.shader.uniformf('actual_size', actual_w, actual_h)
        self.shader.uniformfv('angle_bounds', 1, angle_bounds)
        self.shader.uniformfv('radii', 1, radii)
        self.shader.uniformfv('angles', 1, angles)
        self.shader.uniformi('count', len(radii))
        self.shader.unbind()

    def draw(self):
        """Draw the unwrapped image to the window."""
        glBindTexture(self.texture.target, self.texture.id)
        self.shader.bind()
        self.batch.draw()
        self.shader.unbind()
        glBindTexture(self.texture.target, 0)

    def save_image(self, filename):
        """Save the current window image to the given filename."""
        pyglet.image.get_buffer_manager().get_color_buffer().save(filename)

    def get_fps(self):
        """Get the current framerate in frames per second."""
        return pyglet.clock.get_fps()
开发者ID:shaunlebron,项目名称:super-hexagon-unwrapper,代码行数:67,代码来源:unwrap.py


注:本文中的shader.Shader.uniformfv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。