Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/python_api/examples/gpu.5.py')
-rw-r--r--doc/python_api/examples/gpu.5.py37
1 files changed, 12 insertions, 25 deletions
diff --git a/doc/python_api/examples/gpu.5.py b/doc/python_api/examples/gpu.5.py
index e05290a9442..2edde46a364 100644
--- a/doc/python_api/examples/gpu.5.py
+++ b/doc/python_api/examples/gpu.5.py
@@ -1,39 +1,26 @@
"""
-Mesh with Random Vertex Colors
-------------------------------
+2D Rectangle
+------------
"""
import bpy
import gpu
-import bgl
-import numpy as np
-from random import random
from gpu_extras.batch import batch_for_shader
-mesh = bpy.context.active_object.data
-mesh.calc_loop_triangles()
+vertices = (
+ (100, 100), (300, 100),
+ (100, 200), (300, 200))
-vertices = np.empty((len(mesh.vertices), 3), 'f')
-indices = np.empty((len(mesh.loop_triangles), 3), 'i')
+indices = (
+ (0, 1, 2), (2, 1, 3))
-mesh.vertices.foreach_get(
- "co", np.reshape(vertices, len(mesh.vertices) * 3))
-mesh.loop_triangles.foreach_get(
- "vertices", np.reshape(indices, len(mesh.loop_triangles) * 3))
-
-vertex_colors = [(random(), random(), random(), 1) for _ in range(len(mesh.vertices))]
-
-shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
-batch = batch_for_shader(
- shader, 'TRIS',
- {"pos": vertices, "color": vertex_colors},
- indices=indices,
-)
+shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
+batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)
def draw():
- bgl.glEnable(bgl.GL_DEPTH_TEST)
+ shader.bind()
+ shader.uniform_float("color", (0, 0.5, 0.5, 1.0))
batch.draw(shader)
- bgl.glDisable(bgl.GL_DEPTH_TEST)
-bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')
+bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')