I just copied and pasted from https://docs.blender.org/api/current/gpu.html#d-image:
import bpy
import gpu
import bgl
from gpu_extras.batch import batch_for_shader
IMAGE_NAME = "Untitled"
image = bpy.data.images[IMAGE_NAME]
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)),
},
)
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_int("image", 0)
batch.draw(shader)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL')
But it rendered in black and white colors.
So,
- How to draw colored image?
- How to draw with alpha?
- It doesn't render it immediately - only when I hover over some
view_3d
interface widget. How can I force to draw it immediately?
The problem seems to be SOLVED.
I just can't understand why the image I've tested first time rendered noncolored.
Here is some Screenshots.
Second time I add image it was drawn RGB.
But why it doesn't render immediately? Is there some refresh function operator or etc.?