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
This commit is contained in:
Jacques Lucke 2018-11-13 16:20:16 +01:00
parent c8975b0fc7
commit 77238819f4
1 changed files with 25 additions and 0 deletions

View File

@ -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)