0

我也一直难以适应透明色彩图和一般的透明度。

下面是一个简单的脚本,它应该绘制两个透明的 glumpy 图像,一个在另一个之上。第二个只是覆盖第一个,所以你看不到另一个后面的。

我尝试了不同的 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()
4

1 回答 1

0

我相信上面的问题是由 glumpy 中的一个错误引起的。我已经概述了一个非常简单的补丁,似乎可以解决这里的问题:https ://groups.google.com/forum/#!topic/glumpy-users/UUi4yzl0ktU

于 2014-06-02T15:29:36.583 回答