diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-30 16:50:50 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-30 16:50:50 +0300 |
commit | c3a980436da23a9fbeb4bd4abd1affb481c39bf9 (patch) | |
tree | 70040ff7a659e58be7fd11ebad93bbce9600ca5e /doc/python_api/examples/gpu.8.py | |
parent | 2510bd3a5f35d14f5e0e098c79a776916d273223 (diff) |
Documentation: Replace the bgl API in the gpu module exemples
Diffstat (limited to 'doc/python_api/examples/gpu.8.py')
-rw-r--r-- | doc/python_api/examples/gpu.8.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/doc/python_api/examples/gpu.8.py b/doc/python_api/examples/gpu.8.py index e67c601def9..664f14a23ca 100644 --- a/doc/python_api/examples/gpu.8.py +++ b/doc/python_api/examples/gpu.8.py @@ -7,11 +7,10 @@ If it already exists, it will override the existing one. Currently almost all of the execution time is spent in the last line. In the future this will hopefully be solved by implementing the Python buffer protocol -for :class:`bgl.Buffer` and :class:`bpy.types.Image.pixels` (aka ``bpy_prop_array``). +for :class:`gpu.types.Buffer` and :class:`bpy.types.Image.pixels` (aka ``bpy_prop_array``). """ import bpy import gpu -import bgl import random from mathutils import Matrix from gpu_extras.presets import draw_circle_2d @@ -25,8 +24,8 @@ RING_AMOUNT = 10 offscreen = gpu.types.GPUOffScreen(WIDTH, HEIGHT) with offscreen.bind(): - bgl.glClearColor(0.0, 0.0, 0.0, 0.0) - bgl.glClear(bgl.GL_COLOR_BUFFER_BIT) + fb = gpu.state.active_framebuffer_get() + fb.clear(color=(0.0, 0.0, 0.0, 0.0)) with gpu.matrix.push_pop(): # reset matrices -> use normalized device coordinates [-1, 1] gpu.matrix.load_matrix(Matrix.Identity(4)) @@ -37,9 +36,7 @@ with offscreen.bind(): (random.uniform(-1, 1), random.uniform(-1, 1)), (1, 1, 1, 1), random.uniform(0.1, 1), 20) - buffer = bgl.Buffer(bgl.GL_BYTE, WIDTH * HEIGHT * 4) - bgl.glReadBuffer(bgl.GL_BACK) - bgl.glReadPixels(0, 0, WIDTH, HEIGHT, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer) + buffer = fb.read_color(0, 0, WIDTH, HEIGHT, 4, 0, 'UBYTE') offscreen.free() @@ -48,4 +45,6 @@ if not IMAGE_NAME in bpy.data.images: bpy.data.images.new(IMAGE_NAME, WIDTH, HEIGHT) image = bpy.data.images[IMAGE_NAME] image.scale(WIDTH, HEIGHT) + +buffer.dimensions = WIDTH * HEIGHT * 4 image.pixels = [v / 255 for v in buffer] |