Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/python_api/examples/gpu.6.py')
-rw-r--r--doc/python_api/examples/gpu.6.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/doc/python_api/examples/gpu.6.py b/doc/python_api/examples/gpu.6.py
index 2edde46a364..69af65e163e 100644
--- a/doc/python_api/examples/gpu.6.py
+++ b/doc/python_api/examples/gpu.6.py
@@ -1,25 +1,36 @@
"""
-2D Rectangle
-------------
+2D Image
+--------
+
+To use this example you have to provide an image that should be displayed.
"""
import bpy
import gpu
+import bgl
from gpu_extras.batch import batch_for_shader
-vertices = (
- (100, 100), (300, 100),
- (100, 200), (300, 200))
+IMAGE_NAME = "Untitled"
+image = bpy.data.images[IMAGE_NAME]
-indices = (
- (0, 1, 2), (2, 1, 3))
+shader = gpu.shader.from_builtin('2D_IMAGE')
+batch = batch_for_shader(
+ shader, 'TRI_FAN',
+ {
+ "pos": ((100, 100), (200, 100), (200, 200), (100, 200)),
+ "texCoord": ((0, 0), (1, 0), (1, 1), (0, 1)),
+ },
+)
-shader = gpu.shader.from_builtin('2D_UNIFORM_COLOR')
-batch = batch_for_shader(shader, 'TRIS', {"pos": vertices}, indices=indices)
+if image.gl_load():
+ raise Exception()
def draw():
+ bgl.glActiveTexture(bgl.GL_TEXTURE0)
+ bgl.glBindTexture(bgl.GL_TEXTURE_2D, image.bindcode)
+
shader.bind()
- shader.uniform_float("color", (0, 0.5, 0.5, 1.0))
+ shader.uniform_int("image", 0)
batch.draw(shader)