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
path: root/doc
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2018-11-07 18:13:55 +0300
committerJacques Lucke <mail@jlucke.com>2018-11-07 18:14:11 +0300
commitb82eac89861ee9e67df27dc2fa396352dbb6918d (patch)
treec2928db51e0970bd2c9b73e43ba3265b6eea8c71 /doc
parentc018cea6803beac5e82a6a3770fa86f2d7138300 (diff)
Py API Docs: improve 2D image example
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/gpu.7.py30
1 files changed, 6 insertions, 24 deletions
diff --git a/doc/python_api/examples/gpu.7.py b/doc/python_api/examples/gpu.7.py
index 9f5fb4f5459..486ed5fd411 100644
--- a/doc/python_api/examples/gpu.7.py
+++ b/doc/python_api/examples/gpu.7.py
@@ -1,6 +1,8 @@
"""
2D Image
--------
+
+To use this example you have to provide an image that should be displayed.
"""
import bpy
import gpu
@@ -10,40 +12,20 @@ from gpu_extras.batch import batch_for_shader
IMAGE_NAME = "Untitled"
image = bpy.data.images[IMAGE_NAME]
-coords = [
- (100, 100), (200, 100),
- (100, 200), (200, 200)]
-
-uvs = [(0, 0), (1, 0), (0, 1), (1, 1)]
-
-indices = [(0, 1, 2), (2, 1, 3)]
-
shader = gpu.shader.from_builtin('2D_IMAGE')
-batch = batch_for_shader(shader, 'TRIS',
- {"pos" : coords,
- "texCoord" : uvs},
- indices=indices)
+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))})
-# send image to gpu if it isn't there already
if image.gl_load():
raise Exception()
-# texture identifier on gpu
-texture_id = image.bindcode
-
def draw():
- # in case someone disabled it before
- bgl.glEnable(bgl.GL_TEXTURE_2D)
-
- # bind texture to image unit 0
bgl.glActiveTexture(bgl.GL_TEXTURE0)
- bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture_id)
+ bgl.glBindTexture(bgl.GL_TEXTURE_2D, image.bindcode)
shader.bind()
- # tell shader to use the image that is bound to image unit 0
shader.uniform_int("image", 0)
batch.draw(shader)
- bgl.glDisable(bgl.GL_TEXTURE_2D)
-
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL') \ No newline at end of file