Re: [PyOpenGL-Users] Why glDrawpixels does not render my transparent background?
Brought to you by:
mcfletch
|
From: Ian M. <geo...@gm...> - 2012-02-03 06:29:09
|
2012/2/2 Stéphane ANCELOT <san...@fr...>
> Hi !
>
> I want to render font in opengl with transparent background. The main
> problem is that my background is always opaque black !
>
> Thanks for help.
>
> here is my code :
>
> glEnable(GL_BLEND)
> glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
> font =
> ImageFont.truetype("/usr/share/fonts/truetype/wqy/wqymicrohei.ttc", 16)
> textsize = font.getsize(u"当前运行列表")
> im = Image.new("RGB",textsize,"#000")
> draw = ImageDraw.Draw(im)
> transparent_area = (0,0,im.size[0],im.size[1])
> mask=Image.new('L', im.size, color=0)
> drawmask = ImageDraw.Draw(mask)
> drawmask.rectangle(transparent_area, fill=0)
> im.putalpha(mask)
> draw.text((0,0), u"当前运行列表", font=font, fill="red")
> #im.save('render.png')
> ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0,-1)
> glDrawPixels(ix,iy,GL_RGBA,GL_UNSIGNED_BYTE,image)
That's . . . not really very complete code. As of now, I'd suspect some
sort of issue with setting up the context; you need to request an alpha
buffer.
I notice the commented line--is there an alpha channel in that image?
Ian
|