[Bf-blender-cvs] [77238819f46] blender2.8: Python GPU API: gpu_extras.presets.draw_texture_2d

Jacques Lucke noreply at git.blender.org
Tue Nov 13 16:26:46 CET 2018


Commit: 77238819f46fd53aa4e34636a09c2658abd9ea4f
Author: Jacques Lucke
Date:   Tue Nov 13 16:20:16 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB77238819f46fd53aa4e34636a09c2658abd9ea4f

Python GPU API: gpu_extras.presets.draw_texture_2d

Review wasn't finished yet, but I just commit this for now so that I can make some progress..

Differential Revision: https://developer.blender.org/D3901

===================================================================

M	release/scripts/modules/gpu_extras/presets.py

===================================================================

diff --git a/release/scripts/modules/gpu_extras/presets.py b/release/scripts/modules/gpu_extras/presets.py
index 0365812d022..2bd8d25e46b 100644
--- a/release/scripts/modules/gpu_extras/presets.py
+++ b/release/scripts/modules/gpu_extras/presets.py
@@ -42,3 +42,28 @@ def draw_circle_2d(position, color, radius, segments=32):
         batch.program_set(shader)
         shader.uniform_float("color", color)
         batch.draw()
+
+
+def draw_texture_2d(texture_id, position, width, height):
+    import gpu
+    import bgl
+    from . batch import batch_for_shader
+
+    coords = ((0, 0), (1, 0), (1, 1), (0, 1))
+
+    shader = gpu.shader.from_builtin('2D_IMAGE')
+    batch = batch_for_shader(shader, 'TRI_FAN',
+        {"pos" : coords,
+         "texCoord" : coords})
+
+    bgl.glActiveTexture(bgl.GL_TEXTURE0)
+    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture_id)
+
+    with gpu.matrix.push_pop():
+        gpu.matrix.translate(position)
+        gpu.matrix.scale((width, height))
+
+        shader = gpu.shader.from_builtin('2D_IMAGE')
+        shader.bind()
+        shader.uniform_int("image", 0)
+        batch.draw(shader)



More information about the Bf-blender-cvs mailing list