Re: Why glDrawpixels does not render my transparent background?

Ian Mallett <[email protected]>
Newsgroups gmane.comp.python.opengl.user
Message-ID <CAG4NV=s9q7=vu_cVpEYg+3tfumNGNzAHJ3MZUgWE9bVBz4jexQ@mail.gmail.com>
2012/2/2 Stéphane ANCELOT <[email protected]>

> 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

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2

_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
_______________________________________________
PyOpenGL-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyopengl-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.