Render a TriangleΒΆ

Replicating the WGPU triangle example, but with about 10x less code.

hello triangle
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx


canvas = WgpuCanvas()
renderer = gfx.WgpuRenderer(canvas)
camera = gfx.NDCCamera()

triangle = gfx.Mesh(
    gfx.Geometry(
        indices=[(0, 1, 2)],
        positions=[(0.0, -0.5, 0), (0.5, 0.5, 0), (-0.5, 0.75, 0)],
        colors=[(1, 1, 0, 1), (1, 0, 1, 1), (0, 1, 1, 1)],
    ),
    gfx.MeshBasicMaterial(color_mode="vertex"),
)


if __name__ == "__main__":
    canvas.request_draw(lambda: renderer.render(triangle, camera))
    run()

Total running time of the script: (0 minutes 0.528 seconds)

Gallery generated by Sphinx-Gallery