diff options
author | Jacques Lucke <mail@jlucke.com> | 2018-11-13 18:20:16 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2018-11-13 18:20:16 +0300 |
commit | 77238819f46fd53aa4e34636a09c2658abd9ea4f (patch) | |
tree | beeb4bf4f609f892b04e30f4831910e3b7983fda /release/scripts/modules/gpu_extras | |
parent | c8975b0fc71c0e02f7bb7bc4680077b5745a6931 (diff) |
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
Diffstat (limited to 'release/scripts/modules/gpu_extras')
-rw-r--r-- | release/scripts/modules/gpu_extras/presets.py | 25 |
1 files changed, 25 insertions, 0 deletions
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) |