示例#1
0
            self.use_texture.value = False

            self.light.value = (67.69, -8.14, 52.49)
            self.mvp.write((proj * lookat * rotate).astype('f4').tobytes())

            self.color.value = (0.67, 0.49, 0.29)
            self.objects['ground'].render()

            self.color.value = (0.46, 0.67, 0.29)
            self.objects['grass'].render()

            self.color.value = (1.0, 1.0, 1.0)
            self.objects['billboard'].render()

            self.color.value = (0.2, 0.2, 0.2)
            self.objects['billboard-holder'].render()

            self.use_texture.value = True

            if mode == 'render_to_texture':
                self.texture1.use()

            else:
                self.texture2.use()

            self.objects['billboard-image'].render()


run_example(Example, backend='PyQt5')
示例#2
0
            -0.6,
            -0.8,
            0.6,
            -0.8,
            0.6,
            0.8,
            -0.6,
            0.8,
        ])

        # Indecies are given to specify the order of drawing
        indecies = np.array([0, 1, 2, 0, 3, 4])

        self.vbo = self.ctx.buffer(vertices.astype('f4').tobytes())
        self.ibo = self.ctx.buffer(indecies.astype('i4').tobytes())

        vao_content = [
            # 2 floats are assigned to the 'in' variable named 'in_vert' in the shader code
            (self.vbo, '2f', ['in_vert'])
        ]

        self.vao = self.ctx.vertex_array(self.prog, vao_content, self.ibo)

    def render(self):
        self.ctx.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        self.vao.render()


run_example(Example)
示例#3
0
        self.crate_y += np.random.uniform(-0.2, 0.2, 32 * 32)

    def render(self):
        angle = self.wnd.time * 0.2
        width, height = self.wnd.size
        self.ctx.viewport = self.wnd.viewport
        self.ctx.clear(1.0, 1.0, 1.0)
        self.ctx.enable(ModernGL.DEPTH_TEST)

        camera_pos = (np.cos(angle) * 5.0, np.sin(angle) * 5.0, 2.0)

        proj = Matrix44.perspective_projection(45.0, width / height, 0.1,
                                               1000.0)
        lookat = Matrix44.look_at(
            camera_pos,
            (0.0, 0.0, 0.5),
            (0.0, 0.0, 1.0),
        )

        self.mvp.write((proj * lookat).astype('f4').tobytes())
        self.light.value = camera_pos

        crate_z = np.sin(self.crate_a * self.wnd.time + self.crate_b) * 0.2
        coordinates = np.dstack([self.crate_x, self.crate_y, crate_z])

        self.vbo2.write(coordinates.astype('f4').tobytes())
        self.vao.render(instances=1024)


run_example(InstancedCrates)