首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pygame在glumpy中获得透明度

使用pygame在glumpy中获得透明度
EN

Stack Overflow用户
提问于 2014-06-02 05:14:59
回答 1查看 145关注 0票数 0

我也很难让glumpy能够很好地处理透明的色彩映射和一般的透明度。

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

我已经尝试过不同的opengl启用/禁用命令,但没有使用joy!任何帮助或建议都将不胜感激。

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

发布于 2014-06-02 23:29:37

我相信上面的问题是由glumpy中的一个bug引起的。我在这里概述了一个非常简单的修补程序,它似乎可以纠正这个问题:https://groups.google.com/forum/#!topic/glumpy-users/UUi4yzl0ktU

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23984552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档