[Bf-blender-cvs] [903e5d39729] master: python templates: update operator_modal_draw to 2.8
Philipp Oeser
noreply at git.blender.org
Tue May 21 15:39:18 CEST 2019
Commit: 903e5d39729023883e40641b0fed605a686e72f3
Author: Philipp Oeser
Date: Tue May 21 13:53:17 2019 +0200
Branches: master
https://developer.blender.org/rB903e5d39729023883e40641b0fed605a686e72f3
python templates: update operator_modal_draw to 2.8
part of T56351
Reviewers: JacquesLucke
Differential Revision: https://developer.blender.org/D4912
===================================================================
M release/scripts/templates_py/operator_modal_draw.py
===================================================================
diff --git a/release/scripts/templates_py/operator_modal_draw.py b/release/scripts/templates_py/operator_modal_draw.py
index 6f75d6c632e..5dc72c36a8f 100644
--- a/release/scripts/templates_py/operator_modal_draw.py
+++ b/release/scripts/templates_py/operator_modal_draw.py
@@ -1,7 +1,8 @@
import bpy
import bgl
import blf
-
+import gpu
+from gpu_extras.batch import batch_for_shader
def draw_callback_px(self, context):
print("mouse points", len(self.mouse_path))
@@ -14,20 +15,17 @@ def draw_callback_px(self, context):
blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))
# 50% alpha, 2 pixel width line
+ shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
bgl.glEnable(bgl.GL_BLEND)
- bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
bgl.glLineWidth(2)
-
- bgl.glBegin(bgl.GL_LINE_STRIP)
- for x, y in self.mouse_path:
- bgl.glVertex2i(x, y)
-
- bgl.glEnd()
+ batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": self.mouse_path})
+ shader.bind()
+ shader.uniform_float("color", (0.0, 0.0, 0.0, 0.5))
+ batch.draw(shader)
# restore opengl defaults
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
- bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
class ModalDrawOperator(bpy.types.Operator):
More information about the Bf-blender-cvs
mailing list