Exemplo n.º 1
0
 def _get_final_buffer(self, size):
     render_textures = dict(
         color=Texture(size, unit=0, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}),
         normal=Texture(size, unit=1, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}),
         position=Texture(size, unit=2, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}),            
     )
     return FrameBuffer(size, render_textures, autoclear=True)
Exemplo n.º 2
0
 def _get_shadow_buffer(self, size):
     render_textures = dict(
         # color=Texture(size, unit=0, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}),
         # normal=NormalTexture(size, unit=1, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}),
         # position=NormalTexture(size, unit=2, params={gl.GL_TEXTURE_MIN_FILTER: gl.GL_LINEAR}),            
     )
     return FrameBuffer(size, render_textures, autoclear=True, depth_unit=4)
Exemplo n.º 3
0
 def on_resize(self, width, height):
     self.size = width, height
     # We need to recreate the offscreen buffer if the window size changes
     # This includes when the window is first created.
     render_textures = dict(
         # These will represent the different channels of the framebuffer,
         # that the shader can render to.
         color=Texture(self.size, unit=0),
         normal=NormalTexture(self.size, unit=1),
         position=NormalTexture(self.size, unit=2),
     )
     self.offscreen_buffer = FrameBuffer(self.size,
                                         render_textures,
                                         autoclear=True,
                                         set_viewport=True)
     render_textures2 = dict(color=Texture(self.size, unit=0), )
     self.offscreen_buffer2 = FrameBuffer(self.size,
                                          render_textures2,
                                          autoclear=True,
                                          set_viewport=True)
     return pyglet.event.EVENT_HANDLED  # Work around pyglet internals
Exemplo n.º 4
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        local = Path(__file__).parent

        # Shader setup
        self.view_program = Program(
            VertexShader(local / "glsl/view_vertex.glsl"),
            FragmentShader(local / "glsl/view_fragment.glsl"))
        self.lighting_program = Program(
            VertexShader(local / "glsl/copy_vertex.glsl"),
            FragmentShader(local / "glsl/copy_fragment.glsl"))
        self.copy_program = Program(
            VertexShader(local / "glsl/copy_vertex.glsl"),
            FragmentShader(local / "glsl/simple_copy_frag.glsl"))

        # Load a texture
        texture = ImageTexture(*load_png(local / "textures/plasma.png"),
                               unit=3)

        # Load vertex data from an OBJ file as a "mesh"
        # OBJ file belongs to the Blender project.
        self.suzanne = ObjMesh(local / "obj/suzanne.obj", texture=texture)

        # A simple plane
        plane_size = 3
        self.plane = Mesh(
            [

                # position        color          normal          texture coord
                ((plane_size, plane_size, 0.), (1., 1., 1.), (0., 0., -1.),
                 (1., 1., 1.)),
                ((-plane_size, plane_size, 0.), (1., 1., 1.), (0., 0., -1.),
                 (0., 1., 1.)),
                ((plane_size, -plane_size, 0.), (1., 1., 1.), (0., 0., -1.),
                 (1., 0., 1.)),
                ((-plane_size, -plane_size, 0.), (1., 1., 1.), (0., 0., -1.),
                 (0., 0., 1.)),
            ],
            texture=texture)

        # A framebuffer for rendering the shadow light. It needs only a depth texture.
        self.shadow_size = 256, 256
        self.shadow_buffer = FrameBuffer(self.shadow_size,
                                         autoclear=True,
                                         depth_unit=3,
                                         set_viewport=True)

        self.vao = VertexArrayObject()
Exemplo n.º 5
0
def _get_offscreen_buffer(size):
    return FrameBuffer(size, textures=dict(color=Texture(size, unit=0)))
Exemplo n.º 6
0
 def _get_offscreen_buffer(self, drawing):
     return FrameBuffer(drawing.size,
                        textures=dict(color=Texture(drawing.size, unit=0)))