Esempio n. 1
0
    def __init__(self, width, height):
        """:param width & height: size of the main window in pixels.
        """
        pyglet.window.Window.__init__(
            self,
            width,
            height,
            caption="Polyhedra Mirrors",
            resizable=True,
            visible=False,
            vsync=False,
        )
        self._start_time = time.perf_counter()
        self.shader = Shader([os.path.join(GLSL_DIR, "default.vert")], [
            os.path.join(GLSL_DIR, "common.frag"),
            os.path.join(GLSL_DIR, "data.frag"),
            os.path.join(GLSL_DIR, "main.frag")
        ])

        wood = create_image_texture(WOOD_IMAGE)
        cubemap = create_cubemap_texture(CUBEMAP_IMAGES)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(gl.GL_TEXTURE_CUBE_MAP, cubemap)

        gl.glActiveTexture(gl.GL_TEXTURE1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, wood)

        with self.shader:
            self.shader.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shader.uniformf("iResolution", self.width, self.height, 0.0)
            self.shader.uniformf("iTime", 0.0)
            self.shader.uniformi("iChannel0", 0)
            self.shader.uniformi("iChannel1", 1)
    def __init__(self, width, height):
        """
        :param width and height: size of the window in pixels.
        """
        pyglet.window.Window.__init__(
            self,
            width,
            height,
            caption="Wythoff Explorer",
            resizable=True,
            visible=False,
            vsync=False,
        )
        self._start_time = time.perf_counter()
        self._last = self._now = self._start_time
        self._frame_count = 0  # count number of frames rendered so far
        self.shaderA = Shader(
            ["./glsl/default.vert"],
            [
                "./glsl/wythoff_hyperbolic/common.frag",
                "./glsl/wythoff_hyperbolic/BufferA.frag"
            ],
        )

        self.shaderB = Shader(
            ["./glsl/default.vert"],
            [
                "./glsl/wythoff_hyperbolic/common.frag",
                "./glsl/wythoff_hyperbolic/main.frag"
            ],
        )

        self.font_texture = create_image_texture(FONT_TEXTURE)
        self.noise_texture = create_image_texture(NOISE_TEXTURE)
        self.iChannel0 = pyglet.image.Texture.create_for_size(
            gl.GL_TEXTURE_2D, width, height, gl.GL_RGBA32F_ARB
        )
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(self.iChannel0.target, self.iChannel0.id)
        gl.glActiveTexture(gl.GL_TEXTURE1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.font_texture)
        gl.glActiveTexture(gl.GL_TEXTURE2)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.noise_texture)

        with FrameBuffer() as self.bufferA:
            self.bufferA.attach_texture(self.iChannel0)

        # initialize the shaders
        with self.shaderA:
            self.shaderA.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderA.uniformf("iResolution", width, height, 0.0)
            self.shaderA.uniformf("iTime", 0.0)
            self.shaderA.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderA.uniformi("iChannel0", 0)
            self.shaderA.uniformi("iChannel1", 1)
            self.shaderA.uniformi("iChannel2", 2)
            self.shaderA.uniformf("iDate", *get_idate())
            self.shaderA.uniformf("iTimeDelta", 0)

        with self.shaderB:
            self.shaderB.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderB.uniformf("iResolution", width, height, 0.0)
            self.shaderB.uniformf("iTime", 0.0)
            self.shaderB.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderB.uniformi("iChannel0", 0)
            self.shaderB.uniformi("iChannel1", 1)
            self.shaderB.uniformi("iChannel2", 2)
            self.shaderB.uniformf("iDate", *get_idate())
            self.shaderA.uniformf("iTimeDelta", 0)
Esempio n. 3
0
    def __init__(self, width, height, aa=1, video_rate=16, sample_rate=4):
        """
        :param width and height: size of the window in pixels.

        :param aa: antialiasing level, a higher value will give better
            result but also slow down the animation. (aa=2 is recommended)
        """
        pyglet.window.Window.__init__(
            self,
            width,
            height,
            caption="Wythoff Explorer",
            resizable=True,
            visible=False,
            vsync=False,
        )
        self.video_rate = video_rate
        self.video_on = False
        self.sample_rate = sample_rate
        self._start_time = time.process_time()
        self._frame_count = 0  # count number of frames rendered so far
        self._speed = 4  # control speed of the animation
        self.aa = aa
        # shader A draws the UI
        self.shaderA = Shader(["./glsl/default.vert"], [
            "./glsl/wythoff_polyhedra/common.frag",
            "./glsl/wythoff_polyhedra/BufferA.frag"
        ])
        # shader B draws the polyhedra
        self.shaderB = Shader(["./glsl/default.vert"], [
            "./glsl/wythoff_polyhedra/common.frag",
            "./glsl/wythoff_polyhedra/BufferB.frag"
        ])
        # shader C puts them together
        self.shaderC = Shader(["./glsl/default.vert"], [
            "./glsl/wythoff_polyhedra/common.frag",
            "./glsl/wythoff_polyhedra/main.frag"
        ])
        self.font_texture = create_image_texture(FONT_TEXTURE)
        self.iChannel0 = pyglet.image.Texture.create_for_size(
            gl.GL_TEXTURE_2D, width, height, gl.GL_RGBA32F_ARB)
        self.iChannel1 = pyglet.image.Texture.create_for_size(
            gl.GL_TEXTURE_2D, width, height, gl.GL_RGBA32F_ARB)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(self.iChannel0.target, self.iChannel0.id)
        gl.glActiveTexture(gl.GL_TEXTURE1)
        gl.glBindTexture(self.iChannel1.target, self.iChannel1.id)
        gl.glActiveTexture(gl.GL_TEXTURE2)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self.font_texture)

        # frame buffer A renders the UI to texture iChannel0
        with FrameBuffer() as self.bufferA:
            self.bufferA.attach_texture(self.iChannel0)
        # frame buffer B render the polyhedra to texture iChannel1
        with FrameBuffer() as self.bufferB:
            self.bufferB.attach_texture(self.iChannel1)

        # initialize the shaders

        with self.shaderA:
            self.shaderA.vertex_attrib("position",
                                       [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderA.uniformf("iResolution", width, height, 0.0)
            self.shaderA.uniformf("iTime", 0.0)
            self.shaderA.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderA.uniformi("iChannel0", 0)
            self.shaderA.uniformi("iFrame", 0)

        with self.shaderB:
            self.shaderB.vertex_attrib("position",
                                       [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderB.uniformf("iResolution", width, height, 0.0)
            self.shaderB.uniformf("iTime", 0.0)
            self.shaderB.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderB.uniformi("iChannel0", 0)
            self.shaderB.uniformi("AA", self.aa)

        with self.shaderC:
            self.shaderC.vertex_attrib("position",
                                       [-1, -1, 1, -1, -1, 1, 1, 1])
            self.shaderC.uniformf("iResolution", width, height, 0.0)
            self.shaderC.uniformf("iTime", 0.0)
            self.shaderC.uniformf("iMouse", 0.0, 0.0, 0.0, 0.0)
            self.shaderC.uniformi("iChannel0", 0)
            self.shaderC.uniformi("iChannel1", 1)
            self.shaderC.uniformi("iChannel2", 2)