Hi everyone.
I need to show images inside Blender interface. I found add-on “Sun position”, who does similar what I need. It use bgl module to draw image over the UI. I wrote this code:
class Preview:
def __init__(self, imagepath, context):
self.image_path = imagepath
self.load_image()
self.handler = bpy.types.SpaceProperties.draw_handler_add(
self.render,
(context,), 'WINDOW', 'POST_PIXEL')
self.x = 5
self.y = 70
self.width = 500
self.height = 250
def load_image(self):
self.image = bpy.data.images.load(self.image_path)
self.image.user_clear()
def render(self, context):
bgl.glEnable(bgl.GL_BLEND)
self.image.gl_load(bgl.GL_NEAREST, bgl.GL_NEAREST)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.image.bindcode)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR)
bgl.glTexParameteri(bgl.GL_TEXTURE_2D,
bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR)
bgl.glEnable(bgl.GL_TEXTURE_2D)
bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
bgl.glBegin(bgl.GL_QUADS)
bgl.glTexCoord2f(0.0, 0.0)
bgl.glVertex2f(self.x, self.y)
bgl.glTexCoord2f(1.0, 0.0)
bgl.glVertex2f(self.x + self.width, self.y)
bgl.glTexCoord2f(1.0, 1.0)
bgl.glVertex2f(self.x + self.width, self.y + self.height)
bgl.glTexCoord2f(0.0, 1.0)
bgl.glVertex2f(self.x, self.height + self.y)
bgl.glEnd()
bgl.glDisable(bgl.GL_TEXTURE_2D)
bgl.glFlush()
and it works properly.
But now I have next problem: how to handle events in bgl. I tried to understand it inside sun position code, but I can’t.
Please, explain me.