From 77238819f46fd53aa4e34636a09c2658abd9ea4f Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 13 Nov 2018 16:20:16 +0100 Subject: [PATCH] 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 --- release/scripts/modules/gpu_extras/presets.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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)