Example #1
0
    def __init__(self):
        super().__init__('Demo #1', 1600, 900)

        vertex_code = resources.read_text(glupy.examples.demo01, 'demo01.vert')
        fragment_code = resources.read_text(glupy.examples.demo01, 'demo01.frag')
        self.program = ShaderProgram(vertex_code, fragment_code)

        # # Option 1: Interleaved memory layout.
        # layout = np.dtype(([
        #     ('position', (np.float32, 3)),
        #     ('color', (np.float32, 4)),
        # ], 4), align=True)

        # Option 2: "Struct of arrays" memory layout.
        layout = np.dtype(([
            ('position', (np.float32, 3), 4),
            ('color', (np.float32, 4), 4),
        ]), align=True)

        vertex_data = np.empty(layout.shape, layout.base)
        vertex_data['position'] = [[-1, +1, 0], [+1, +1, 0], [-1, -1, 0], [+1, -1, 0]]
        vertex_data['color'] = [[0, 1, 0, 1], [1, 1, 0, 1], [1, 0, 0, 1], [0, 0, 1, 1]]

        index_data = np.asarray([
            0, 1, 2,
            3, 1, 2,
        ], dtype=np.uint32)

        self.vao = VAO(VBO(vertex_data), EBO(index_data), connect_to=self.program)
Example #2
0
    def __init__(self):
        w, h = 512, 512
        super().__init__('Demo #3', w, h)

        # Ensure PyTorch CUDA is initialised (it is important that this happens _after_ PyCUDA
        # initialises its context, which is currently done via autoinit).
        assert torch.cuda.is_available()
        torch.empty(1, device='cuda')

        # Create a texture buffer with OpenGL and CUDA views
        self.tex = MappedTexture(h, w)

        vertex_code = resources.read_text(glupy.examples.demo03, 'demo03.vert')
        fragment_code = resources.read_text(glupy.examples.demo03,
                                            'demo03.frag')
        self.program = ShaderProgram(vertex_code, fragment_code)

        vertex_data = np.empty(4, [
            ('position', np.float32, 2),
            ('texcoord', np.float32, 2),
        ])

        vertex_data['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
        vertex_data['texcoord'] = [(0, 0), (0, 1), (1, 0), (1, 1)]

        self.vao = VAO(vbo=VBO(vertex_data), connect_to=self.program)

        self.theta = 0
Example #3
0
    def __init__(self):
        super().__init__('Demo #2', 1600, 900)

        gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)

        vertex_code = resources.read_text(glupy.examples.demo02, 'demo02.vert')
        fragment_code = resources.read_text(glupy.examples.demo02, 'demo02.frag')
        self.program = ShaderProgram(vertex_code, fragment_code)

        vertex_data = np.empty(8, [
            ('position', np.float32, 3),
            ('color', np.float32, 4),
        ])
        index_data = np.empty(12 * 3, dtype=np.uint32)

        vertex_data['position'] = [
            (-1, -1, -1),
            (+1, -1, -1),
            (+1, +1, -1),
            (-1, +1, -1),
            (-1, -1, +1),
            (+1, -1, +1),
            (+1, +1, +1),
            (-1, +1, +1),
        ]
        vertex_data['color'] = [
            (0, 1, 0, 1),
            (1, 1, 0, 1),
            (1, 0, 0, 1),
            (0, 0, 1, 1),
            (1, 1, 1, 1),
            (1, 1, 1, 1),
            (1, 1, 1, 1),
            (1, 1, 1, 1),
        ]

        index_data[:] = [
            0, 1, 2,
            2, 3, 0,
            1, 5, 6,
            6, 2, 1,
            7, 6, 5,
            5, 4, 7,
            4, 0, 3,
            3, 7, 4,
            4, 5, 1,
            1, 0, 4,
            3, 2, 6,
            6, 7, 3
        ]

        self.vao = VAO(vbo=VBO(vertex_data), ebo=EBO(index_data), connect_to=self.program)

        trans_model = mat4.scale(0.5) #@ mat4.rotate_axis_angle(0, 1/np.sqrt(2), 1/np.sqrt(2), np.pi / 4)
        trans_view = mat4.translate(2.0, 0, 5.0)
        trans_proj = mat4.perspective(np.pi / 3, 16 / 9, 0.1, 100)

        with self.program:
            self.program.set_uniform_mat4('transModel', trans_model)
            self.program.set_uniform_mat4('transView', trans_view)
            self.program.set_uniform_mat4('transProj', trans_proj)
Example #4
0
def create_simple_shader():
    return ShaderProgram(resources.read_text(posekit.gui.res, 'simple.vert'),
                         resources.read_text(posekit.gui.res, 'simple.frag'))
Example #5
0
def create_seekbar_shader():
    return ShaderProgram(resources.read_text(posekit.gui.res, 'image.vert'),
                         resources.read_text(posekit.gui.res, 'seekbar.frag'))
Example #6
0
def create_checkerboard_shader():
    return ShaderProgram(resources.read_text(posekit.gui.res, 'checkerboard.vert'),
                         resources.read_text(posekit.gui.res, 'checkerboard.frag'))