gpu.6.py 526 B

123456789101112131415161718192021222324252627
  1. """
  2. 2D Rectangle
  3. ------------
  4. """
  5. import bpy
  6. import gpu
  7. from gpu_extras.batch import batch_for_shader
  8. vertices = (
  9. (100, 100), (300, 100),
  10. (100, 200), (300, 200))
  11. indices = (
  12. (0, 1, 2), (2, 1, 3))
  13. shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
  14. batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)
  15. def draw():
  16. shader.bind()
  17. shader.uniform_float("color", (0, 0.5, 0.5, 1.0))
  18. batch.draw(shader)
  19. bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')