Here's a pared back example. I've put a bunch of comments on the line
which causes trouble. Essentially, when I don't draw the glumpy image
the gl lines look fine. As soon as I draw it, anywhere it seems, the
gl lines have "wrong" colors.
import numpy, glumpy
import Image
import pdb
import numpy as np
import OpenGL
import OpenGL.GL as gl
import OpenGL.GLU as glu
import OpenGL.GLUT as glut
refimg = np.random.uniform(0,1, (512,512,4)).astype(np.float32)
refimg[:,:,3] = np.ones_like(refimg[:,:,3])
img = np.ones((100,100,4)).astype(np.float32)
img *= (0,0,1.,.5)
fig = glumpy.figure( (512,512) )
grefimg = glumpy.Image(refimg)
image = glumpy.Image(img)
image.x = 0.
image.y = 0.
grefimg.x = 0.
grefimg.y = 0.
@fig.event
def on_init():
print 'Inititalization'
@fig.event
def on_draw():
print 'Drawing requested'
fig.clear()
gl.glEnable( gl.GL_BLEND )
gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA )
grefimg.update()
### THIS IS THE LINE THAT CAUSES TROUBLE.
### IF IT IS COMMENTED OUT THE LINES DRAWN WITH THE OPEN GL CALLS
LOOK PROPERLY RED
### IF IT IS UNCOMMENTED, THE GL LINES LOOK BLOOD RED.
grefimg.draw(-200.,-200., 0., width=fig.width,height=fig.height)
# draw some simple lines
gl.glDisable(gl.GL_BLEND)
radius = 10.
gl.glPushMatrix()
gl.glLoadIdentity()
gl.glTranslatef(50,50,1.)
gl.glLineWidth(10.0)
gl.glDisable(gl.GL_BLEND)
gl.glBegin(gl.GL_LINE_LOOP)
gl.glColor4f(1.0,0.0,0.0,1.0)
for angle in np.arange(0.,2*np.pi,(2*np.pi)/100.):
gl.glVertex3f(np.sin(angle) * radius, np.cos(angle) *
radius, 0.)
gl.glEnd()
gl.glPopMatrix()
# draw some simple lines
radius = 10.
gl.glPushMatrix()
gl.glLoadIdentity()
gl.glTranslatef(400,400,1.)
gl.glLineWidth(10.0)
gl.glDisable(gl.GL_BLEND)
gl.glBegin(gl.GL_LINE_LOOP)
gl.glColor4f(1.0,0.0,0.0,1.0)
for angle in np.arange(0.,2*np.pi,(2*np.pi)/100.):
gl.glVertex3f(np.sin(angle) * radius, np.cos(angle) *
radius, 0.)
gl.glEnd()
gl.glPopMatrix()
@fig.event
def on_mouse_motion(x, y, dx, dy):
print 'Mouse motion (x=%.1f, y=%.1f, dx=%.1f, dy=%.1f)' % (x,y,dx,dy)
@fig.event
def on_mouse_drag(x, y, dx, dy, button):
print 'Mouse drag (x=%.1f, y=%.1f, dx=%.1f, dy=%.1f, button=%d)' %
(x,y,dx,dy,button)
image.x = image.x + dx
image.y = image.y + dy
fig.redraw()
fig.show()