私はまた、透明なカラーマップや一般的な透明度でうまく動作するように不機嫌になるのに苦労しています。
以下は、2 つの透明でぎこちない画像を重ねて描画する単純なスクリプトです。2 番目は 1 番目を上書きするだけなので、後ろにあるものは見えません。
さまざまなopenglの有効化/無効化コマンドを試しましたが、喜びはありません! どんな助けや提案も大歓迎です。
from pylab import *
import pygame
from pygame.locals import *
import glumpy
import OpenGL.GL as gl
import OpenGL.GLU as glu
# Set the width and height of the screen [width,height]
size=[256,256]
screen=pygame.display.set_mode(size,OPENGL|DOUBLEBUF)
## I think something here might get this to work, but I've
## experimented turining these off and on. Any suggestions?
gl.glDisable(gl.GL_DEPTH_TEST)
gl.glDisable(gl.GL_LIGHTING)
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
a = np.random.rand(256,256).astype('f')
a[0:128,:] = 1.0
b = np.random.rand(256,256).astype('f')
b[:,0:128] = 1.0
# cmaps
aCM = glumpy.colormap.Colormap("Rd", (0., (1.,1.,0.,0.0)), (1., (1.0,0.0,0.0,1.0)))
bCM = glumpy.colormap.Colormap("Bl", (0., (0.,1.0,1.,0.0)), (1., (0.0,0.0,1.0,1.0)))
# glumpy images
ai = glumpy.image.Image(a,colormap=aCM)
bi = glumpy.image.Image(b,colormap=bCM)
print('press q or ESC to quit')
while True :
gl.glPushMatrix()
gl.glLoadIdentity()
gl.glViewport(0, 0, size[0],size[1])
# draw a diagonal line underneath everything
gl.glColor4d(1,0,0,1)
gl.glBegin(gl.GL_LINES)
gl.glVertex3d(0,0,-0.1)
gl.glVertex3d(1,1.0,-0.1)
gl.glEnd()
# draw the glumpy images, with ai beneath bi
ai.draw(x=-1,y=-1,z=0,width=2.0,height=2.0)
bi.draw(x=-.9,y=-.9,z=0.1,width=1.8,height=2.0)
gl.glPopMatrix()
pygame.display.flip()
gl.glClearColor(0.1, 0.1, 0.1, 0.1);
gl.glClear(gl.GL_COLOR_BUFFER_BIT);
for event in pygame.event.get(): # User did something
if event.type == pygame.KEYDOWN:
if event.key in [pygame.K_q, pygame.K_ESCAPE] :
pygame.quit()
sys.exit()