How to draw using bgl on single View3D only?

Hi,

I’m trying to draw simple image in 3D viewport. It works quite well, but it displays image on every 3D view.
Here is code for to display image I use:

def draw_IR_preview(self, context, region):
    
    if region.type == 'WINDOW':
        viewWidth = region.width
        viewHeight = region.height    
        x1 = 0
        y1 = 0
        x2 = viewWidth
        y2 = viewHeight
        color=[1,1,1,1]
        try:
            img = bpy.data.images['ir.bmp']
            img.reload()
        except:
            img = bpy.data.images.load(os.path.join(exportPath, 'ir.bmp'))
        img.gl_load(bgl.GL_NEAREST, bgl.GL_NEAREST)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, img.bindcode)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2f(0,0)
        bgl.glVertex2f(x1,y1)
        bgl.glTexCoord2f(0,1)
        bgl.glVertex2f(x1,y2)
        bgl.glTexCoord2f(1,1)
        bgl.glVertex2f(x2,y2)
        bgl.glTexCoord2f(1,0)
        bgl.glVertex2f(x2,y1)        
        bgl.glEnd()

Is there any way to draw on specific 3D view instead of all?

So how do I use the script? I have an image named ‘ir.bmp’, I run the script and nothing happens. what activates it?

It is activated by operator.
If you want to learn more about this then look here:
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Screencast_Key_Status_Tool

IDK, my bgl stuff just draws in one region:


Your operator is modal so it’s probably preventing from redrawing other 3D views.
My isn’t modal. The same problem is with. i.e. Screencast Keys addon. It displays on each 3D View.
I don’t know if this is Blender error, feature or just limitation :frowning:

Ah, probably the ‘problem’ is that the callback functions are shared for all the different space types so on every refresh they go down the list and do whatever the callback function tells them to do – in this case draw some stuff in the 3dview.

I’d imagine it’d be possible to have the callbacks as a per-instance property (attached to the view3d struct or whatever) – actually, come to think of it, I have no idea how they work since I’m not really a fan of the current implementation so never really looked into them.

try
looking at the
# ====== OPERATOR METHOD OVERLOADS ====== #
in enhanced 3d cursor in contrib

So at last, did this problem solved? I can not draw 2d shapes on a single 3d view, the drawing display on all 3d views.