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


Python Scene.set_uniforms方法代码示例

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


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

示例1: __init__

# 需要导入模块: from scene import Scene [as 别名]
# 或者: from scene.Scene import set_uniforms [as 别名]

#.........这里部分代码省略.........
            self.ray_shader = self.create_shader(vert_read, ray_frag.read())
            self.std_shader = self.create_shader(vert_read, std_frag.read())

        self.setup(self.ray_shader, self.std_shader)
        self.setup_uniforms()

    def create_shader(self, vert, frag):
        return compileProgram(
            compileShader(vert, GL_VERTEX_SHADER),
            compileShader(frag, GL_FRAGMENT_SHADER)
        )

    def setup(self, ray_shader, std_shader):
        verts = numpy.array(
        #    verts    uv
            [-1,  1,  0,  1,
              1,  1,  1,  1,
              1, -1,  1,  0,
             -1, -1,  0,  0],
            dtype=numpy.float32)

        self.vbo = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
        glBufferData(GL_ARRAY_BUFFER, 4*len(verts), verts, GL_STATIC_DRAW)

        position = glGetAttribLocation(std_shader, 'position')
        glEnableVertexAttribArray(position)
        glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 4*4, None)

        texcoord = glGetAttribLocation(std_shader, 'texcoord')
        glEnableVertexAttribArray(texcoord)
        glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 4*4,
            ctypes.c_void_p(4*2))

        self.draw_texture = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, self.draw_texture)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.width, self.height, 0,
            GL_RGBA, GL_FLOAT, None)

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

        self.fbo = glGenFramebuffers(1)
        glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
            GL_TEXTURE_2D, self.draw_texture, 0)

        if glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE:
            raise Exception('well... fuck.')

    def setup_uniforms(self):
        glUseProgram(self.ray_shader)
        self.scene.setup_uniforms(self.ray_shader, self.uniforms)

    def set_uniforms(self):
        self.scene.set_uniforms(self.uniforms)

    def draw(self):
        glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
        glViewport(0, 0, self.width, self.height)
        glClear(GL_COLOR_BUFFER_BIT);
        glUseProgram(self.ray_shader)
        self.set_uniforms()

        glBindTexture(GL_TEXTURE_2D, self.draw_texture)
        glDrawArrays(GL_QUADS, 0, 4)

        glBindFramebuffer(GL_FRAMEBUFFER, 0)
        glViewport(0, 0, self.real_width, self.real_height)
        glClear(GL_COLOR_BUFFER_BIT);
        glUseProgram(self.std_shader)

        glBindTexture(GL_TEXTURE_2D, self.draw_texture)
        glDrawArrays(GL_QUADS, 0, 4)

        pygame.display.flip()
        self.clock.tick()
        print str(self.clock.get_fps()) + '\r',

    def handle_events(self):
        e = pygame.event.poll()

        if e.type == pygame.QUIT:
            self.running = False
        elif e.type == pygame.KEYUP and e.key == pygame.K_RETURN:
            self.reload()

        self.scene.update(e, self.clock.get_time()/1000.0)

    def quit(self):
        glDeleteTextures([self.draw_texture])
        glDeleteFramebuffers(1, [self.fbo])
        glDeleteProgram(self.ray_shader)
        glDeleteProgram(self.std_shader)
        glDeleteBuffers(1, [self.vbo])

        pygame.display.quit()
        pygame.quit()
开发者ID:bakerj76,项目名称:march,代码行数:104,代码来源:marchgl.py


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