Re: Trying to draw text on a pixbuf



I was doing this a while ago.

Specifically, I was using Pango to create text for OpenGL textures, but I needed to have rendered text with an alpha channel to do that, just like you do.

Pango is pretty shit in that it won't (as far as I can tell) render an alpha channel. I mean how basic is that?

You can't just render onto a black background and then set black to be transparent, as remember that the text could be antialised.

What I did was to render white text on a black background into a pixbuf, add an alpha channel (there's a function for that) then itterate through each pixel in the pixbuf, copying the red channel into the alpha channel (remember we rendered white on black, so the text will be opaque and the background transparent), and then setting the red green and blue channels to be whatever colour I wanted.

You can then render that pixbuf.

There will be some very slight artifacts does to sub pixel antialisiaing, so I wouldn'e be writing GIMP's text tool using this. Anyone not knowledgeable about antialiasing will probably not notice it though.

Chris

Frédéric Terraza wrote:
Hello,

this is my first post ever on a mailing-list, I hope I'm doing it the right way. My apologies if not so.

I'd like to draw text on a pixbuf. I first tried :
- to write text in a PangoLayout
- to render the layout in a pixmap
- to copy the pixmap in the pixbuf

It worked, but the text has a black background that overlap the previously drawn things on the pixbuf. And I can't change the background color (with a gdk_gc_set_background for example).

So, I tried :
- to render the pixmap in a temporary pixbuf
- to add alpha to this pixbuf, making black become transparent
- to copy this temporary pixbuf in my final pixbuf.

Same results. And I don't know why.

Maybe alpha isn't taken into account by gdk_pixbuf_copy_area ? If so, I suppose it's not too hard to make another version of this primitive doing that (but slow). And since it bothers me to have black as background color (what will I do if the foreground color is also black ? It may happen with text), do you have an idea for how to change the background color ?

Thanks in advance. And excuse my english, school is far away now...

Fred
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]