2012/2/2 Stéphane ANCELOT <sancelot@free.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