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.clock() self._last = self._now = self._start_time self._frame_count = 0 # count number of frames rendered so far self.shaderA = Shader( ["./glsl_wythoff/wythoff.vert"], ["./glsl_wythoff/common.frag", "./glsl_wythoff/BufferA.frag"]) self.shaderB = Shader( ["./glsl_wythoff/wythoff.vert"], ["./glsl_wythoff/common.frag", "./glsl_wythoff/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)
def __init__(self, width, height, pqr, AA=2): """ :param width and height: size of the window in pixels. :param pqr: Coxeter diagram of the tessellation. :param AA: antialiasing level. """ pyglet.window.Window.__init__( self, width, height, caption="Hyperbolic Honeycomb {}-{}-{}".format(*pqr), resizable=True, visible=False, vsync=False) self.pqr = pqr self._start_time = time.clock() self.shader = Shader(["./glsl/hyperbolic3d.vert"], ["./glsl/hyperbolic3d.frag"]) self.buffer = pyglet.image.get_buffer_manager().get_color_buffer() # create the texture texture = create_image_texture(IMG_PATH) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glBindTexture(gl.GL_TEXTURE_2D, texture) 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("iTexture", 0) self.shader.uniformf("pqr", *self.pqr) self.shader.uniformi("AA", AA)
def __init__(self, width, height, aa): pyglet.window.Window.__init__( self, width, height, caption="Loxodromic transformation", resizable=True, visible=False, vsync=False, ) self._start_time = time.clock() self.shader = Shader(["./glsl/loxodrome.vert"], ["./glsl/loxodrome.frag"]) self.buffer = pyglet.image.get_buffer_manager().get_color_buffer() texture = create_image_texture(WOOD_TEXTURE) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glBindTexture(gl.GL_TEXTURE_2D, texture) with self.shader: self.shader.vertex_attrib("position", [-1, -1, 1, -1, -1, 1, 1, 1]) self.shader.uniformf("iResolution", width, height, 0.0) self.shader.uniformf("iTime", 0.0) self.shader.uniformi("iTexture", 0) self.shader.uniformi("AA", aa)
def __init__(self, width, height, aa=1): """ :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._start_time = time.clock() self._frame_count = 0 # count number of frames rendered so far self._speed = 20 # control speed of the animation self.aa = aa # shader A draws the UI self.shaderA = Shader(["./glsl/wythoff.vert"], ["./glsl/common.frag", "./glsl/BufferA.frag"]) # shadwr B draws the polyhedra self.shaderB = Shader(["./glsl/wythoff.vert"], ["./glsl/common.frag", "./glsl/BufferB.frag"]) # shader C puts them together self.shaderC = Shader(["./glsl/wythoff.vert"], ["./glsl/common.frag", "./glsl/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("iTexture", 2)