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-13 18:38:12 +0300
committerJacques Lucke <mail@jlucke.com>2018-11-13 18:38:12 +0300
commit3aa30406dd0f862f8360741ff77118505aa93302 (patch)
treeeeedb899096cdeeb902fcd4f857c242df663234d /doc
parentdc6ba4f2ec1f66e4c182ef7e651da6badf6497aa (diff)
Py API Docs: New Example for off screen rendering
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/gpu.10.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/doc/python_api/examples/gpu.10.py b/doc/python_api/examples/gpu.10.py
new file mode 100644
index 00000000000..aa5574c44bb
--- /dev/null
+++ b/doc/python_api/examples/gpu.10.py
@@ -0,0 +1,38 @@
+"""
+Rendering the 3D View into a Texture
+------------------------------------
+
+The scene has to have a camera for this example to work.
+You could also make this independent of a specific camera, but Blender does not expose good functions to create view and projection matrices yet.
+"""
+import bpy
+import bgl
+import gpu
+from gpu_extras.presets import draw_texture_2d
+
+WIDTH = 512
+HEIGHT = 256
+
+offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT)
+
+def draw():
+ context = bpy.context
+ scene = context.scene
+
+ view_matrix = scene.camera.matrix_world.inverted()
+
+ projection_matrix = scene.camera.calc_matrix_camera(
+ context.depsgraph, x=WIDTH, y=HEIGHT)
+
+ offscreen.draw_view3d(
+ scene,
+ context.view_layer,
+ context.space_data,
+ context.region,
+ view_matrix,
+ projection_matrix)
+
+ bgl.glDisable(bgl.GL_DEPTH_TEST)
+ draw_texture_2d(offscreen.color_texture, (10, 10), WIDTH, HEIGHT)
+
+bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL') \ No newline at end of file