diff options
Diffstat (limited to 'doc/python_api/examples/gpu.8.py')
-rw-r--r-- | doc/python_api/examples/gpu.8.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/doc/python_api/examples/gpu.8.py b/doc/python_api/examples/gpu.8.py index 7e41164fc7e..56cbb93c61a 100644 --- a/doc/python_api/examples/gpu.8.py +++ b/doc/python_api/examples/gpu.8.py @@ -2,10 +2,10 @@ Generate a texture using Offscreen Rendering -------------------------------------------- -1. Create an :class:`gpu.types.GPUOffScreen` object. -2. Draw some circles into it. -3. Make a new shader for drawing a planar texture in 3D. -4. Draw the generated texture using the new shader. +#. Create an :class:`gpu.types.GPUOffScreen` object. +#. Draw some circles into it. +#. Make a new shader for drawing a planar texture in 3D. +#. Draw the generated texture using the new shader. """ import bpy import gpu @@ -19,8 +19,7 @@ from gpu_extras.presets import draw_circle_2d offscreen = gpu.types.GPUOffScreen(512, 512) -offscreen.bind() -try: +with offscreen.bind(): bgl.glClear(bgl.GL_COLOR_BUFFER_BIT) with gpu.matrix.push_pop(): # reset matrices -> use normalized device coordinates [-1, 1] @@ -31,8 +30,6 @@ try: for i in range(-amount, amount + 1): x_pos = i / amount draw_circle_2d((x_pos, 0.0), (1, 1, 1, 1), 0.5, 200) -finally: - offscreen.unbind() # Drawing the generated texture in 3D space @@ -66,9 +63,13 @@ fragment_shader = ''' ''' shader = gpu.types.GPUShader(vertex_shader, fragment_shader) -batch = batch_for_shader(shader, 'TRI_FAN', - {"position" : ((-1, -1), (1, -1), (1, 1), (-1, 1)), - "uv" : ((0, 0), (1, 0), (1, 1), (0, 1))}) +batch = batch_for_shader( + shader, 'TRI_FAN', + { + "position": ((-1, -1), (1, -1), (1, 1), (-1, 1)), + "uv": ((0, 0), (1, 0), (1, 1), (0, 1)), + }, +) def draw(): @@ -81,4 +82,5 @@ def draw(): shader.uniform_float("image", 0) batch.draw(shader) -bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')
\ No newline at end of file + +bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW') |